Skip to content

Commit

Permalink
Remove last non OO commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rougier committed Jul 3, 2020
1 parent aab94f3 commit a953246
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 16 deletions.
Binary file modified cheatsheets-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified cheatsheets-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified cheatsheets.pdf
Binary file not shown.
26 changes: 13 additions & 13 deletions cheatsheets.tex
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,8 @@
fig, ax = plt.subplots()\\
ax.plot(X,Y,color='C1')\\
\\
plt.savefig(``figure.pdf'')\\
plt.show() }
fig.savefig(``figure.pdf'')\\
fig.show() }
\end{myboxed}
\vspace{\fill}

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

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

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

\includegraphics[width=\columnwidth]{fonts.pdf}
\end{myboxed}
Expand Down Expand Up @@ -916,7 +916,7 @@

\begin{myboxed}{Legend placement}
\includegraphics[width=\columnwidth]{legend-placement.pdf}
plt.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\
ax.\textbf{legend}(loc="string", bbox\_to\_anchor=(x,y))\\
\begin{tabular}{@{}p{0.33\columnwidth}
p{0.33\columnwidth}
p{0.33\columnwidth}@{}}
Expand Down Expand Up @@ -961,9 +961,9 @@
\textbf{… resize a figure?}\\
\hspace*{2.5mm}~$\rightarrow$ fig.set\_size\_inches(w,h)\\
\textbf{… save a figure?}\\
\hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf")\\
\hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf")\\
\textbf{… save a transparent figure?}\\
\hspace*{2.5mm}~$\rightarrow$ plt.savefig("figure.pdf", transparent=True)\\
\hspace*{2.5mm}~$\rightarrow$ fig.savefig("figure.pdf", transparent=True)\\
\textbf{… clear a figure?}\\
\hspace*{2.5mm}~$\rightarrow$ ax.clear()\\
\textbf{… close all figures?}\\
Expand All @@ -973,11 +973,11 @@
\textbf{… remove tick labels ?}\\
\hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticklabels([])\\
\textbf{… rotate tick labels ?}\\
\hspace*{2.5mm}~$\rightarrow$ plt.[xy]ticks(rotation=90)\\
\hspace*{2.5mm}~$\rightarrow$ ax.set\_[xy]ticks(rotation=90)\\
\textbf{… hide top spine?}\\
\hspace*{2.5mm}~$\rightarrow$ ax.spines['top'].set\_visible(False)\\
\textbf{… hide legend border?}\\
\hspace*{2.5mm}~$\rightarrow$ plt.legend(frameon=False)\\
\hspace*{2.5mm}~$\rightarrow$ ax.legend(frameon=False)\\
\textbf{… show error as shaded region?}\\
\hspace*{2.5mm}~$\rightarrow$ ax.fill\_between(X, Y+error, Y-error)\\
\textbf{… draw a rectangle?}\\
Expand All @@ -997,7 +997,7 @@
\textbf{… get a discrete colormap?}\\
\hspace*{2.5mm}~$\rightarrow$ plt.get\_cmap(``viridis'', 10)\\
\textbf{… show a figure for one second?}\\
\hspace*{2.5mm}~$\rightarrow$ plt.show(block=False), time.sleep(1)
\hspace*{2.5mm}~$\rightarrow$ fig.show(block=False), time.sleep(1)
\end{myboxed}
%
\vspace{\fill}
Expand Down
Binary file modified handout-tips.pdf
Binary file not shown.
Binary file modified handout-tips.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions handout-tips.tex
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ \subsection*{\rmfamily Multiline plot}
X,Y = [], []
for x in np.linspace(0, 10*np.pi, 100):
X.extend([x, x, None]), Y.extend([0, sin(x), None])
plt.plot(X, Y, "black")
ax.plot(X, Y, "black")
\end{lstlisting}
\includegraphics[width=\linewidth]{tip-multiline.pdf}

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

0 comments on commit a953246

Please sign in to comment.