Skip to content

Commit 0157212

Browse files
committed
from __future__ import print_function so print works same for Python 2 & 3
1 parent 8d71325 commit 0157212

4 files changed

+55
-38
lines changed

AnatomyOfMatplotlib-Part0-Intro2NumPy.ipynb

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:90ccb5909624353434d7af8f1073a89ba8f8f43775a430cf536d07701670eb19"
4+
"signature": "sha256:291c02e0eda1008690ba35d47865fd743d899737c6c702e384430e08988052a0"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
88
"worksheets": [
99
{
1010
"cells": [
11+
{
12+
"cell_type": "code",
13+
"collapsed": false,
14+
"input": [
15+
"# Let printing work the same in Python 2 and 3\n",
16+
"from __future__ import print_function"
17+
],
18+
"language": "python",
19+
"metadata": {},
20+
"outputs": []
21+
},
1122
{
1223
"cell_type": "markdown",
1324
"metadata": {},
@@ -39,9 +50,9 @@
3950
"collapsed": false,
4051
"input": [
4152
"a = np.array([1, 2, 3])\n",
42-
"print a.shape\n",
43-
"print a.size\n",
44-
"print a.ndim"
53+
"print(a.shape)\n",
54+
"print(a.size)\n",
55+
"print(a.ndim)"
4556
],
4657
"language": "python",
4758
"metadata": {},
@@ -52,9 +63,9 @@
5263
"collapsed": false,
5364
"input": [
5465
"x = np.arange(100)\n",
55-
"print x.shape\n",
56-
"print x.size\n",
57-
"print x.ndim"
66+
"print(x.shape)\n",
67+
"print(x.size)\n",
68+
"print(x.ndim)"
5869
],
5970
"language": "python",
6071
"metadata": {},
@@ -65,9 +76,9 @@
6576
"collapsed": false,
6677
"input": [
6778
"y = np.random.rand(5, 80)\n",
68-
"print y.shape\n",
69-
"print y.size\n",
70-
"print y.ndim"
79+
"print(y.shape)\n",
80+
"print(y.size)\n",
81+
"print(y.ndim)"
7182
],
7283
"language": "python",
7384
"metadata": {},
@@ -86,7 +97,7 @@
8697
"collapsed": false,
8798
"input": [
8899
"x.shape = (20, 5)\n",
89-
"print x"
100+
"print(x)"
90101
],
91102
"language": "python",
92103
"metadata": {},
@@ -104,7 +115,7 @@
104115
"collapsed": false,
105116
"input": [
106117
"y.shape = (4, 20, -1)\n",
107-
"print y.shape"
118+
"print(y.shape)"
108119
],
109120
"language": "python",
110121
"metadata": {},
@@ -122,7 +133,7 @@
122133
"collapsed": false,
123134
"input": [
124135
"# Scalar Indexing\n",
125-
"print x[2]"
136+
"print(x[2])"
126137
],
127138
"language": "python",
128139
"metadata": {},
@@ -133,7 +144,7 @@
133144
"collapsed": false,
134145
"input": [
135146
"# Slicing\n",
136-
"print x[2:5]"
147+
"print(x[2:5])"
137148
],
138149
"language": "python",
139150
"metadata": {},
@@ -144,10 +155,10 @@
144155
"collapsed": false,
145156
"input": [
146157
"# Advanced slicing\n",
147-
"print \"First 5 rows\\n\", x[:5]\n",
148-
"print \"Row 18 to the end\\n\", x[18:]\n",
149-
"print \"Last 5 rows\\n\", x[-5:]\n",
150-
"print \"Reverse the rows\\n\", x[::-1]"
158+
"print(\"First 5 rows\\n\", x[:5])\n",
159+
"print(\"Row 18 to the end\\n\", x[18:])\n",
160+
"print(\"Last 5 rows\\n\", x[-5:])\n",
161+
"print(\"Reverse the rows\\n\", x[::-1])"
151162
],
152163
"language": "python",
153164
"metadata": {},
@@ -158,7 +169,7 @@
158169
"collapsed": false,
159170
"input": [
160171
"# Boolean Indexing\n",
161-
"print x[(x % 2) == 0]"
172+
"print(x[(x % 2) == 0])"
162173
],
163174
"language": "python",
164175
"metadata": {},
@@ -169,7 +180,7 @@
169180
"collapsed": false,
170181
"input": [
171182
"# Fancy Indexing -- Note the use of a list, not tuple!\n",
172-
"print x[[1, 3, 8, 9, 2]]"
183+
"print(x[[1, 3, 8, 9, 2]])"
173184
],
174185
"language": "python",
175186
"metadata": {},
@@ -187,8 +198,8 @@
187198
"cell_type": "code",
188199
"collapsed": true,
189200
"input": [
190-
"print \"Shape of X:\", x.shape\n",
191-
"print \"Shape of Y:\", y.shape"
201+
"print(\"Shape of X:\", x.shape)\n",
202+
"print(\"Shape of Y:\", y.shape)"
192203
],
193204
"language": "python",
194205
"metadata": {},
@@ -206,13 +217,13 @@
206217
"collapsed": false,
207218
"input": [
208219
"a = x + y\n",
209-
"print a.shape\n",
220+
"print(a.shape)\n",
210221
"b = x[np.newaxis, :, :] + y\n",
211-
"print b.shape\n",
222+
"print(b.shape)\n",
212223
"c = np.tile(x, (4, 1, 1)) + y\n",
213-
"print c.shape\n",
214-
"print \"Are a and b identical?\", np.all(a == b)\n",
215-
"print \"Are a and c identical?\", np.all(a == c)"
224+
"print(c.shape)\n",
225+
"print(\"Are a and b identical?\", np.all(a == b))\n",
226+
"print(\"Are a and c identical?\", np.all(a == c))"
216227
],
217228
"language": "python",
218229
"metadata": {},
@@ -231,9 +242,9 @@
231242
"input": [
232243
"x = np.arange(-5, 5, 0.1)\n",
233244
"y = np.arange(-8, 8, 0.25)\n",
234-
"print x.shape, y.shape\n",
245+
"print(x.shape, y.shape)\n",
235246
"z = x[np.newaxis, :] * y[:, np.newaxis]\n",
236-
"print z.shape"
247+
"print(z.shape)"
237248
],
238249
"language": "python",
239250
"metadata": {},
@@ -245,9 +256,9 @@
245256
"input": [
246257
"# More concisely\n",
247258
"y, x = np.ogrid[-8:8:0.25, -5:5:0.1]\n",
248-
"print x.shape, y.shape\n",
259+
"print(x.shape, y.shape)\n",
249260
"z = x * y\n",
250-
"print z.shape"
261+
"print(z.shape)"
251262
],
252263
"language": "python",
253264
"metadata": {},

AnatomyOfMatplotlib-Part1-pyplot.ipynb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:c7159e6f4ecac56d72f7333ed9bb24bbfeb4c66fba3000a1b2cb3c382fd148fd"
4+
"signature": "sha256:6302a88e9db31d8d9cfae2b0103e57708f94b802a561930d11298cd246e9d590"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -12,6 +12,8 @@
1212
"cell_type": "code",
1313
"collapsed": false,
1414
"input": [
15+
"# Let printing work the same in Python 2 and 3\n",
16+
"from __future__ import print_function\n",
1517
"# Turning on inline plots -- just for use in ipython notebooks.\n",
1618
"%matplotlib inline"
1719
],
@@ -64,8 +66,8 @@
6466
"collapsed": false,
6567
"input": [
6668
"import matplotlib\n",
67-
"print matplotlib.__version__\n",
68-
"print matplotlib.get_backend()"
69+
"print(matplotlib.__version__)\n",
70+
"print(matplotlib.get_backend())"
6971
],
7072
"language": "python",
7173
"metadata": {},

AnatomyOfMatplotlib-Part2-HowToSpeakMPL.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:e1f772cda181207fb767d95705c04a7a3d95f8d83188cf282ca42ddd7bde2d9c"
4+
"signature": "sha256:fd78007a40ee7741b1dcfaa7d2433f856d967b938376774e12322eeccaf2f9ec"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -12,6 +12,8 @@
1212
"cell_type": "code",
1313
"collapsed": false,
1414
"input": [
15+
"# Let printing work the same in Python 2 and 3\n",
16+
"from __future__ import print_function\n",
1517
"# Turning on inline plots -- just for use in ipython notebooks.\n",
1618
"%matplotlib inline\n",
1719
"import numpy as np\n",
@@ -574,7 +576,7 @@
574576
"collapsed": false,
575577
"input": [
576578
"import matplotlib\n",
577-
"print matplotlib.matplotlib_fname()"
579+
"print(matplotlib.matplotlib_fname())"
578580
],
579581
"language": "python",
580582
"metadata": {},

AnatomyOfMatplotlib-Part3-Artists.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"metadata": {
33
"name": "",
4-
"signature": "sha256:8e508bf3316b2a5e920e25f9597d595277a37bede03ba337428c5c16762373a7"
4+
"signature": "sha256:0ed463ce3e3c15589941f95292232da728af5c8fd4698e2ece99a953d2619171"
55
},
66
"nbformat": 3,
77
"nbformat_minor": 0,
@@ -12,6 +12,8 @@
1212
"cell_type": "code",
1313
"collapsed": false,
1414
"input": [
15+
"# Let printing work the same in Python 2 and 3\n",
16+
"from __future__ import print_function\n",
1517
"# Turning on inline plots -- just for use in ipython notebooks.\n",
1618
"%matplotlib inline\n",
1719
"import numpy as np\n",
@@ -171,7 +173,7 @@
171173
"collapsed": false,
172174
"input": [
173175
"fig, ax = plt.subplots(1, 1)\n",
174-
"print plt.getp(fig.patch)"
176+
"print(plt.getp(fig.patch))"
175177
],
176178
"language": "python",
177179
"metadata": {},

0 commit comments

Comments
 (0)