34
34
showtabs=false,
35
35
tabsize=2,
36
36
%
37
- emph = { plot, scatter, imshow, bar, contourf, pie, subplots,
38
- errorbar, boxplot, hist, title, xlabel, ylabel , suptitle },
37
+ emph = { plot, scatter, imshow, bar, contourf, pie, subplots, show, savefig,
38
+ errorbar, boxplot, hist, set_title, set_xlabel, set_ylabel , suptitle, },
39
39
emphstyle = {\ttfamily\bfseries }
40
40
}
41
41
@@ -89,8 +89,9 @@ \section*{\LARGE \rmfamily
89
89
%
90
90
\fbox {3} \textbf {Render }
91
91
\ begin{lstlisting}
92
- plt.plot(X, Y)
93
- plt.show()
92
+ fig, ax = plt.subplots()
93
+ ax.plot(X, Y)
94
+ fig.show()
94
95
\end {lstlisting }
95
96
%
96
97
\fbox {4} \textbf {Observe } \medskip \\
@@ -106,7 +107,7 @@ \subsection*{\rmfamily Choose}
106
107
\ begin{lstlisting} [belowskip=-\baselineskip]
107
108
X = np.random.uniform(0, 1, 100)
108
109
Y = np.random.uniform(0, 1, 100)
109
- plt .scatter(X, Y)
110
+ ax .scatter(X, Y)
110
111
\end {lstlisting }
111
112
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{basic-scatter.pdf}}
112
113
\end {tabular }
@@ -115,7 +116,7 @@ \subsection*{\rmfamily Choose}
115
116
\ begin{lstlisting} [belowskip=-\baselineskip]
116
117
X = np.arange(10)
117
118
Y = np.random.uniform(1, 10, 10)
118
- plt .bar(X, Y)
119
+ ax .bar(X, Y)
119
120
\end {lstlisting }
120
121
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{basic-bar.pdf}}
121
122
\end {tabular }
@@ -124,7 +125,7 @@ \subsection*{\rmfamily Choose}
124
125
\ begin{lstlisting} [belowskip=-\baselineskip]
125
126
Z = np.random.uniform(0, 1, (8,8)
126
127
127
- plt .imshow(Z)
128
+ ax .imshow(Z)
128
129
\end {lstlisting }
129
130
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{basic-imshow.pdf}}
130
131
\end {tabular }
@@ -133,7 +134,7 @@ \subsection*{\rmfamily Choose}
133
134
\ begin{lstlisting} [belowskip=-\baselineskip]
134
135
Z = np.random.uniform(0, 1, (8,8)
135
136
136
- plt .contourf(Z)
137
+ ax .contourf(Z)
137
138
\end {lstlisting }
138
139
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{basic-contour.pdf}}
139
140
\end {tabular }
@@ -142,7 +143,7 @@ \subsection*{\rmfamily Choose}
142
143
\ begin{lstlisting} [belowskip=-\baselineskip]
143
144
Z = np.random.uniform(0, 1, 4)
144
145
145
- plt .pie(Z)
146
+ ax .pie(Z)
146
147
\end {lstlisting }
147
148
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{basic-pie.pdf}}
148
149
\end {tabular }
@@ -151,7 +152,7 @@ \subsection*{\rmfamily Choose}
151
152
\ begin{lstlisting} [belowskip=-\baselineskip]
152
153
Z = np.random.normal(0, 1, 100)
153
154
154
- plt .hist(Z)
155
+ ax .hist(Z)
155
156
\end {lstlisting }
156
157
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{advanced-hist.pdf}}
157
158
\end {tabular }
@@ -160,7 +161,7 @@ \subsection*{\rmfamily Choose}
160
161
\ begin{lstlisting} [belowskip=-\baselineskip]
161
162
X = np.arange(5)
162
163
Y = np.random.uniform(0,1,5)
163
- plt .errorbar(X, Y, Y/4)
164
+ ax .errorbar(X, Y, Y/4)
164
165
\end {lstlisting }
165
166
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{advanced-errorbar.pdf}}
166
167
\end {tabular }
@@ -169,7 +170,7 @@ \subsection*{\rmfamily Choose}
169
170
\ begin{lstlisting} [belowskip=-\baselineskip]
170
171
Z = np.random.normal(0,1,(100,3))
171
172
172
- plt .boxplot(Z)
173
+ ax .boxplot(Z)
173
174
\end {lstlisting }
174
175
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{advanced-boxplot.pdf}}
175
176
\end {tabular }
@@ -187,7 +188,7 @@ \subsection*{\rmfamily Tweak}
187
188
\ begin{lstlisting} [belowskip=-\baselineskip]
188
189
X = np.linspace(0,10,100)
189
190
Y = np.sin(X)
190
- plt .plot(X, Y, color="black")
191
+ ax .plot(X, Y, color="black")
191
192
\end {lstlisting }
192
193
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{plot-color.pdf}}
193
194
\end {tabular }
@@ -196,7 +197,7 @@ \subsection*{\rmfamily Tweak}
196
197
\ begin{lstlisting} [belowskip=-\baselineskip]
197
198
X = np.linspace(0,10,100)
198
199
Y = np.sin(X)
199
- plt .plot(X, Y, linestyle="--")
200
+ ax .plot(X, Y, linestyle="--")
200
201
\end {lstlisting }
201
202
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{plot-linestyle.pdf}}
202
203
\end {tabular }
@@ -205,7 +206,7 @@ \subsection*{\rmfamily Tweak}
205
206
\ begin{lstlisting} [belowskip=-\baselineskip]
206
207
X = np.linspace(0,10,100)
207
208
Y = np.sin(X)
208
- plt .plot(X, Y, linewidth=5)
209
+ ax .plot(X, Y, linewidth=5)
209
210
\end {lstlisting }
210
211
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{plot-linewidth.pdf}}
211
212
\end {tabular }
@@ -214,7 +215,7 @@ \subsection*{\rmfamily Tweak}
214
215
\ begin{lstlisting} [belowskip=-\baselineskip]
215
216
X = np.linspace(0,10,100)
216
217
Y = np.sin(X)
217
- plt .plot(X, Y, marker="o")
218
+ ax .plot(X, Y, marker="o")
218
219
\end {lstlisting }
219
220
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{plot-marker.pdf}}
220
221
\end {tabular }
@@ -232,7 +233,7 @@ \subsection*{\rmfamily Organize}
232
233
\ begin{lstlisting} [belowskip=-\baselineskip]
233
234
X = np.linspace(0,10,100)
234
235
Y1, Y1 = np.sin(X), np.cos(X)
235
- plt .plot(X, Y1, Y2)
236
+ ax .plot(X, Y1, Y2)
236
237
\end {lstlisting }
237
238
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{plot-multi.pdf}}
238
239
\end {tabular }
@@ -261,18 +262,18 @@ \subsection*{\rmfamily Label \mdseries (everything)}
261
262
% -----------------------------------------------------------------------------
262
263
\begin {tabular }{@{}m{.821\linewidth }m{.169\linewidth }}
263
264
\ begin{lstlisting} [belowskip=-\baselineskip]
264
- plt .plot(X, Y)
265
- plt .suptitle(None)
266
- plt.title ("A Sine wave")
265
+ ax .plot(X, Y)
266
+ fig .suptitle(None)
267
+ ax.set_title ("A Sine wave")
267
268
\end {lstlisting }
268
269
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{plot-title.pdf}}
269
270
\end {tabular }
270
271
% -----------------------------------------------------------------------------
271
272
\begin {tabular }{@{}m{.821\linewidth }m{.169\linewidth }}
272
273
\ begin{lstlisting} [belowskip=-\baselineskip]
273
- plt .plot(X, Y)
274
- plt.ylabel (None)
275
- plt.xlabel ("Time")
274
+ ax .plot(X, Y)
275
+ ax.set_ylabel (None)
276
+ ax.set_xlabel ("Time")
276
277
\end {lstlisting }
277
278
& \raisebox {-0.75em}{\includegraphics [width=\linewidth ]{plot-xlabel.pdf}}
278
279
\end {tabular }
@@ -289,8 +290,8 @@ \subsection*{\rmfamily Explore}
289
290
\subsection* {\rmfamily Save \mdseries (bitmap or vector format) }
290
291
% -----------------------------------------------------------------------------
291
292
\ begin{lstlisting} [belowskip=-\baselineskip]
292
- plt.savefif ("my-first-figure.png", dpi=300)
293
- plt .savefig("my-first-figure.pdf")
293
+ fig.savefig ("my-first-figure.png", dpi=300)
294
+ fig .savefig("my-first-figure.pdf")
294
295
\end {lstlisting }
295
296
%
296
297
\vfill
0 commit comments