Skip to content

Commit a953246

Browse files
committed
Remove last non OO commands
1 parent aab94f3 commit a953246

7 files changed

+16
-16
lines changed

cheatsheets-1.png

-174 Bytes
Loading

cheatsheets-2.png

252 Bytes
Loading

cheatsheets.pdf

13 Bytes
Binary file not shown.

cheatsheets.tex

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@
279279
fig, ax = plt.subplots()\\
280280
ax.plot(X,Y,color='C1')\\
281281
\\
282-
plt.savefig(``figure.pdf'')\\
283-
plt.show() }
282+
fig.savefig(``figure.pdf'')\\
283+
fig.show() }
284284
\end{myboxed}
285285
\vspace{\fill}
286286

@@ -713,7 +713,7 @@
713713
ax.\textbf{tick\_params}(width=10, …)\\
714714
ax.\textbf{set\_axis\_[on|off]}()\\
715715
\\
716-
plt.\textbf{tight\_layout}()\\
716+
ax.\textbf{tight\_layout}()\\
717717
plt.\textbf{gcf}(), plt.\textbf{gca}()\\
718718
mpl.\textbf{rc}('axes', linewidth=1, …)\\
719719
fig.patch.\textbf{set\_alpha}(0)\\
@@ -781,7 +781,7 @@
781781
%
782782
\begin{myboxed}{Extent \& origin \hfill
783783
\API{https://matplotlib.org/tutorials/intermediate/imshow_extent.html} }
784-
plt.\textbf{imshow}( extent=…, origin=… )\\
784+
ax.\textbf{imshow}( extent=…, origin=… )\\
785785

786786
\includegraphics[width=\columnwidth]{extents.pdf}
787787
\end{myboxed}
@@ -790,7 +790,7 @@
790790
%
791791
\begin{myboxed}{Text alignments \hfill
792792
\API{https://matplotlib.org/tutorials/text/text_props.html} }
793-
plt.\textbf{text}( …, ha=… , va=…, … )\\
793+
ax.\textbf{text}( …, ha=… , va=…, … )\\
794794

795795
\includegraphics[width=\columnwidth]{text-alignments.pdf}
796796
\end{myboxed}
@@ -799,8 +799,8 @@
799799
%
800800
\begin{myboxed}{Text parameters \hfill
801801
\API{https://matplotlib.org/tutorials/text/text_props.html}}
802-
plt.\textbf{text}( …, family=… , size=…, weight = …)\\
803-
plt.\textbf{text}( …, fontproperties = … )\\
802+
ax.\textbf{text}( …, family=… , size=…, weight = …)\\
803+
ax.\textbf{text}( …, fontproperties = … )\\
804804

805805
\includegraphics[width=\columnwidth]{fonts.pdf}
806806
\end{myboxed}
@@ -916,7 +916,7 @@
916916

917917
\begin{myboxed}{Legend placement}
918918
\includegraphics[width=\columnwidth]{legend-placement.pdf}
919-
plt.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\
919+
ax.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\
920920
\begin{tabular}{@{}p{0.33\columnwidth}
921921
p{0.33\columnwidth}
922922
p{0.33\columnwidth}@{}}
@@ -961,9 +961,9 @@
961961
\textbf{… resize a figure?}\\
962962
\hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w,h)\\
963963
\textbf{… save a figure?}\\
964-
\hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf")\\
964+
\hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf")\\
965965
\textbf{… save a transparent figure?}\\
966-
\hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf", transparent=True)\\
966+
\hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf", transparent=True)\\
967967
\textbf{… clear a figure?}\\
968968
\hspace*{2.5mm}~$\rightarrow$ ax.clear()\\
969969
\textbf{… close all figures?}\\
@@ -973,11 +973,11 @@
973973
\textbf{… remove tick labels ?}\\
974974
\hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticklabels([])\\
975975
\textbf{… rotate tick labels ?}\\
976-
\hspace*{2.5mm}~$\rightarrow$ plt.[xy]ticks(rotation=90)\\
976+
\hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticks(rotation=90)\\
977977
\textbf{… hide top spine?}\\
978978
\hspace*{2.5mm}~$\rightarrow$ ax.spines['top'].set\_visible(False)\\
979979
\textbf{… hide legend border?}\\
980-
\hspace*{2.5mm}~$\rightarrow$ plt.legend(frameon=False)\\
980+
\hspace*{2.5mm}~$\rightarrow$ ax.legend(frameon=False)\\
981981
\textbf{… show error as shaded region?}\\
982982
\hspace*{2.5mm}~$\rightarrow$ ax.fill\_between(X, Y+error, Y-error)\\
983983
\textbf{… draw a rectangle?}\\
@@ -997,7 +997,7 @@
997997
\textbf{… get a discrete colormap?}\\
998998
\hspace*{2.5mm}~$\rightarrow$ plt.get\_cmap(``viridis'', 10)\\
999999
\textbf{… show a figure for one second?}\\
1000-
\hspace*{2.5mm}~$\rightarrow$ plt.show(block=False), time.sleep(1)
1000+
\hspace*{2.5mm}~$\rightarrow$ fig.show(block=False), time.sleep(1)
10011001
\end{myboxed}
10021002
%
10031003
\vspace{\fill}

handout-tips.pdf

2 Bytes
Binary file not shown.

handout-tips.png

-215 Bytes
Loading

handout-tips.tex

Lines changed: 3 additions & 3 deletions
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)