Skip to content

Commit 329e0ba

Browse files
authored
Merge pull request #15 from matplotlib/nicolas
Nicolas
2 parents 54b8bc1 + a953246 commit 329e0ba

10 files changed

+51
-44
lines changed

cheatsheets-1.png

4.59 KB
Loading

cheatsheets-2.png

4.21 KB
Loading

cheatsheets.pdf

7.23 KB
Binary file not shown.

cheatsheets.tex

+22-16
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@
7070
UprightFont = Regular,
7171
ItalicFont = Italic,
7272
BoldFont = Bold ]
73+
\newfontfamily\RobotoSlab{Robot Slab} [
74+
Path = fonts/roboto-slab/RobotoSlab-,
75+
Extension = .ttf,
76+
UprightFont = Light,
77+
BoldFont = Regular ]
7378
\newfontfamily\Roboto{Roboto}[
7479
Path = fonts/roboto/Roboto-, Extension = .ttf,
7580
UprightFont = Regular,
@@ -224,17 +229,18 @@
224229
rightline=true,
225230
leftline=true,
226231
bottomline=true,
227-
linecolor=black!10,
232+
linecolor=black!0,
228233
frametitleaboveskip=0.5em,
229234
frametitlebelowskip=0.5em,
230235
innerbottommargin=.5\baselineskip,
231236
innerrightmargin=.5em,
232237
innerleftmargin=.5em,
233238
%userdefinedwidth=1\textwidth,
234-
frametitle={\scshape \bfseries \sffamily #1},
239+
% frametitle={\scshape \bfseries \sffamily #1},
240+
frametitle={\footnotesize \RobotoSlab \bfseries \hspace*{0mm} #1},
235241
% frametitlerule=true,
236242
%frametitlerulecolor=red,
237-
frametitlebackgroundcolor=black!10,
243+
frametitlebackgroundcolor=black!5,
238244
frametitlerulewidth=2pt]}
239245
{\end{mdframed}}
240246

@@ -273,8 +279,8 @@
273279
fig, ax = plt.subplots()\\
274280
ax.plot(X,Y,color='C1')\\
275281
\\
276-
plt.savefig(``figure.pdf'')\\
277-
plt.show() }
282+
fig.savefig(``figure.pdf'')\\
283+
fig.show() }
278284
\end{myboxed}
279285
\vspace{\fill}
280286

@@ -707,7 +713,7 @@
707713
ax.\textbf{tick\_params}(width=10, …)\\
708714
ax.\textbf{set\_axis\_[on|off]}()\\
709715
\\
710-
plt.\textbf{tight\_layout}()\\
716+
ax.\textbf{tight\_layout}()\\
711717
plt.\textbf{gcf}(), plt.\textbf{gca}()\\
712718
mpl.\textbf{rc}('axes', linewidth=1, …)\\
713719
fig.patch.\textbf{set\_alpha}(0)\\
@@ -775,7 +781,7 @@
775781
%
776782
\begin{myboxed}{Extent \& origin \hfill
777783
\API{https://matplotlib.org/tutorials/intermediate/imshow_extent.html} }
778-
plt.\textbf{imshow}( extent=…, origin=… )\\
784+
ax.\textbf{imshow}( extent=…, origin=… )\\
779785

780786
\includegraphics[width=\columnwidth]{extents.pdf}
781787
\end{myboxed}
@@ -784,7 +790,7 @@
784790
%
785791
\begin{myboxed}{Text alignments \hfill
786792
\API{https://matplotlib.org/tutorials/text/text_props.html} }
787-
plt.\textbf{text}( …, ha=… , va=…, … )\\
793+
ax.\textbf{text}( …, ha=… , va=…, … )\\
788794

789795
\includegraphics[width=\columnwidth]{text-alignments.pdf}
790796
\end{myboxed}
@@ -793,8 +799,8 @@
793799
%
794800
\begin{myboxed}{Text parameters \hfill
795801
\API{https://matplotlib.org/tutorials/text/text_props.html}}
796-
plt.\textbf{text}( …, family=… , size=…, weight = …)\\
797-
plt.\textbf{text}( …, fontproperties = … )\\
802+
ax.\textbf{text}( …, family=… , size=…, weight = …)\\
803+
ax.\textbf{text}( …, fontproperties = … )\\
798804

799805
\includegraphics[width=\columnwidth]{fonts.pdf}
800806
\end{myboxed}
@@ -910,7 +916,7 @@
910916

911917
\begin{myboxed}{Legend placement}
912918
\includegraphics[width=\columnwidth]{legend-placement.pdf}
913-
plt.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\
919+
ax.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\
914920
\begin{tabular}{@{}p{0.33\columnwidth}
915921
p{0.33\columnwidth}
916922
p{0.33\columnwidth}@{}}
@@ -955,9 +961,9 @@
955961
\textbf{… resize a figure?}\\
956962
\hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w,h)\\
957963
\textbf{… save a figure?}\\
958-
\hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf")\\
964+
\hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf")\\
959965
\textbf{… save a transparent figure?}\\
960-
\hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf", transparent=True)\\
966+
\hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf", transparent=True)\\
961967
\textbf{… clear a figure?}\\
962968
\hspace*{2.5mm}~$\rightarrow$ ax.clear()\\
963969
\textbf{… close all figures?}\\
@@ -967,11 +973,11 @@
967973
\textbf{… remove tick labels ?}\\
968974
\hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticklabels([])\\
969975
\textbf{… rotate tick labels ?}\\
970-
\hspace*{2.5mm}~$\rightarrow$ plt.[xy]ticks(rotation=90)\\
976+
\hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticks(rotation=90)\\
971977
\textbf{… hide top spine?}\\
972978
\hspace*{2.5mm}~$\rightarrow$ ax.spines['top'].set\_visible(False)\\
973979
\textbf{… hide legend border?}\\
974-
\hspace*{2.5mm}~$\rightarrow$ plt.legend(frameon=False)\\
980+
\hspace*{2.5mm}~$\rightarrow$ ax.legend(frameon=False)\\
975981
\textbf{… show error as shaded region?}\\
976982
\hspace*{2.5mm}~$\rightarrow$ ax.fill\_between(X, Y+error, Y-error)\\
977983
\textbf{… draw a rectangle?}\\
@@ -991,7 +997,7 @@
991997
\textbf{… get a discrete colormap?}\\
992998
\hspace*{2.5mm}~$\rightarrow$ plt.get\_cmap(``viridis'', 10)\\
993999
\textbf{… show a figure for one second?}\\
994-
\hspace*{2.5mm}~$\rightarrow$ plt.show(block=False), time.sleep(1)
1000+
\hspace*{2.5mm}~$\rightarrow$ fig.show(block=False), time.sleep(1)
9951001
\end{myboxed}
9961002
%
9971003
\vspace{\fill}

handout-beginner.pdf

761 Bytes
Binary file not shown.

handout-beginner.png

8.34 KB
Loading

handout-beginner.tex

+26-25
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
showtabs=false,
3535
tabsize=2,
3636
%
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, },
3939
emphstyle = {\ttfamily\bfseries}
4040
}
4141

@@ -89,8 +89,9 @@ \section*{\LARGE \rmfamily
8989
%
9090
\fbox{3} \textbf{Render}
9191
\begin{lstlisting}
92-
plt.plot(X, Y)
93-
plt.show()
92+
fig, ax = plt.subplots()
93+
ax.plot(X, Y)
94+
fig.show()
9495
\end{lstlisting}
9596
%
9697
\fbox{4} \textbf{Observe} \medskip\\
@@ -106,7 +107,7 @@ \subsection*{\rmfamily Choose}
106107
\begin{lstlisting}[belowskip=-\baselineskip]
107108
X = np.random.uniform(0, 1, 100)
108109
Y = np.random.uniform(0, 1, 100)
109-
plt.scatter(X, Y)
110+
ax.scatter(X, Y)
110111
\end{lstlisting}
111112
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{basic-scatter.pdf}}
112113
\end{tabular}
@@ -115,7 +116,7 @@ \subsection*{\rmfamily Choose}
115116
\begin{lstlisting}[belowskip=-\baselineskip]
116117
X = np.arange(10)
117118
Y = np.random.uniform(1, 10, 10)
118-
plt.bar(X, Y)
119+
ax.bar(X, Y)
119120
\end{lstlisting}
120121
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{basic-bar.pdf}}
121122
\end{tabular}
@@ -124,7 +125,7 @@ \subsection*{\rmfamily Choose}
124125
\begin{lstlisting}[belowskip=-\baselineskip]
125126
Z = np.random.uniform(0, 1, (8,8)
126127

127-
plt.imshow(Z)
128+
ax.imshow(Z)
128129
\end{lstlisting}
129130
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{basic-imshow.pdf}}
130131
\end{tabular}
@@ -133,7 +134,7 @@ \subsection*{\rmfamily Choose}
133134
\begin{lstlisting}[belowskip=-\baselineskip]
134135
Z = np.random.uniform(0, 1, (8,8)
135136

136-
plt.contourf(Z)
137+
ax.contourf(Z)
137138
\end{lstlisting}
138139
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{basic-contour.pdf}}
139140
\end{tabular}
@@ -142,7 +143,7 @@ \subsection*{\rmfamily Choose}
142143
\begin{lstlisting}[belowskip=-\baselineskip]
143144
Z = np.random.uniform(0, 1, 4)
144145

145-
plt.pie(Z)
146+
ax.pie(Z)
146147
\end{lstlisting}
147148
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{basic-pie.pdf}}
148149
\end{tabular}
@@ -151,7 +152,7 @@ \subsection*{\rmfamily Choose}
151152
\begin{lstlisting}[belowskip=-\baselineskip]
152153
Z = np.random.normal(0, 1, 100)
153154

154-
plt.hist(Z)
155+
ax.hist(Z)
155156
\end{lstlisting}
156157
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{advanced-hist.pdf}}
157158
\end{tabular}
@@ -160,7 +161,7 @@ \subsection*{\rmfamily Choose}
160161
\begin{lstlisting}[belowskip=-\baselineskip]
161162
X = np.arange(5)
162163
Y = np.random.uniform(0,1,5)
163-
plt.errorbar(X, Y, Y/4)
164+
ax.errorbar(X, Y, Y/4)
164165
\end{lstlisting}
165166
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{advanced-errorbar.pdf}}
166167
\end{tabular}
@@ -169,7 +170,7 @@ \subsection*{\rmfamily Choose}
169170
\begin{lstlisting}[belowskip=-\baselineskip]
170171
Z = np.random.normal(0,1,(100,3))
171172

172-
plt.boxplot(Z)
173+
ax.boxplot(Z)
173174
\end{lstlisting}
174175
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{advanced-boxplot.pdf}}
175176
\end{tabular}
@@ -187,7 +188,7 @@ \subsection*{\rmfamily Tweak}
187188
\begin{lstlisting}[belowskip=-\baselineskip]
188189
X = np.linspace(0,10,100)
189190
Y = np.sin(X)
190-
plt.plot(X, Y, color="black")
191+
ax.plot(X, Y, color="black")
191192
\end{lstlisting}
192193
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-color.pdf}}
193194
\end{tabular}
@@ -196,7 +197,7 @@ \subsection*{\rmfamily Tweak}
196197
\begin{lstlisting}[belowskip=-\baselineskip]
197198
X = np.linspace(0,10,100)
198199
Y = np.sin(X)
199-
plt.plot(X, Y, linestyle="--")
200+
ax.plot(X, Y, linestyle="--")
200201
\end{lstlisting}
201202
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-linestyle.pdf}}
202203
\end{tabular}
@@ -205,7 +206,7 @@ \subsection*{\rmfamily Tweak}
205206
\begin{lstlisting}[belowskip=-\baselineskip]
206207
X = np.linspace(0,10,100)
207208
Y = np.sin(X)
208-
plt.plot(X, Y, linewidth=5)
209+
ax.plot(X, Y, linewidth=5)
209210
\end{lstlisting}
210211
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-linewidth.pdf}}
211212
\end{tabular}
@@ -214,7 +215,7 @@ \subsection*{\rmfamily Tweak}
214215
\begin{lstlisting}[belowskip=-\baselineskip]
215216
X = np.linspace(0,10,100)
216217
Y = np.sin(X)
217-
plt.plot(X, Y, marker="o")
218+
ax.plot(X, Y, marker="o")
218219
\end{lstlisting}
219220
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-marker.pdf}}
220221
\end{tabular}
@@ -232,7 +233,7 @@ \subsection*{\rmfamily Organize}
232233
\begin{lstlisting}[belowskip=-\baselineskip]
233234
X = np.linspace(0,10,100)
234235
Y1, Y1 = np.sin(X), np.cos(X)
235-
plt.plot(X, Y1, Y2)
236+
ax.plot(X, Y1, Y2)
236237
\end{lstlisting}
237238
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-multi.pdf}}
238239
\end{tabular}
@@ -261,18 +262,18 @@ \subsection*{\rmfamily Label \mdseries (everything)}
261262
% -----------------------------------------------------------------------------
262263
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
263264
\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")
267268
\end{lstlisting}
268269
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-title.pdf}}
269270
\end{tabular}
270271
% -----------------------------------------------------------------------------
271272
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
272273
\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")
276277
\end{lstlisting}
277278
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-xlabel.pdf}}
278279
\end{tabular}
@@ -289,8 +290,8 @@ \subsection*{\rmfamily Explore}
289290
\subsection*{\rmfamily Save \mdseries (bitmap or vector format)}
290291
% -----------------------------------------------------------------------------
291292
\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")
294295
\end{lstlisting}
295296
%
296297
\vfill

handout-tips.pdf

2 Bytes
Binary file not shown.

handout-tips.png

-215 Bytes
Loading

handout-tips.tex

+3-3
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ \subsection*{\rmfamily Multiline plot}
157157
X,Y = [], []
158158
for x in np.linspace(0, 10*np.pi, 100):
159159
X.extend([x, x, None]), Y.extend([0, sin(x), None])
160-
plt.plot(X, Y, "black")
160+
ax.plot(X, Y, "black")
161161
\end{lstlisting}
162162
\includegraphics[width=\linewidth]{tip-multiline.pdf}
163163

@@ -166,9 +166,9 @@ \subsection*{\rmfamily Dotted lines}
166166
To have rounded dotted lines, use a custom {\ttfamily linestyle} and
167167
modify {\ttfamily dash\_capstyle}.
168168
\begin{lstlisting}
169-
plt.plot([0,1], [0,0], "C1",
169+
ax.plot([0,1], [0,0], "C1",
170170
linestyle = (0, (0.01, 1)), dash_capstyle="round")
171-
plt.plot([0,1], [1,1], "C1",
171+
ax.plot([0,1], [1,1], "C1",
172172
linestyle = (0, (0.01, 2)), dash_capstyle="round")
173173
\end{lstlisting}
174174
\includegraphics[width=\linewidth]{tip-dotted.pdf}

0 commit comments

Comments
 (0)