Skip to content

Nicolas #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
38 changes: 22 additions & 16 deletions cheatsheets.tex
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
UprightFont = Regular,
ItalicFont = Italic,
BoldFont = Bold ]
\newfontfamily\RobotoSlab{Robot Slab} [
Path = fonts/roboto-slab/RobotoSlab-,
Extension = .ttf,
UprightFont = Light,
BoldFont = Regular ]
\newfontfamily\Roboto{Roboto}[
Path = fonts/roboto/Roboto-, Extension = .ttf,
UprightFont = Regular,
Expand Down Expand Up @@ -224,17 +229,18 @@
rightline=true,
leftline=true,
bottomline=true,
linecolor=black!10,
linecolor=black!0,
frametitleaboveskip=0.5em,
frametitlebelowskip=0.5em,
innerbottommargin=.5\baselineskip,
innerrightmargin=.5em,
innerleftmargin=.5em,
%userdefinedwidth=1\textwidth,
frametitle={\scshape \bfseries \sffamily #1},
% frametitle={\scshape \bfseries \sffamily #1},
frametitle={\footnotesize \RobotoSlab \bfseries \hspace*{0mm} #1},
% frametitlerule=true,
%frametitlerulecolor=red,
frametitlebackgroundcolor=black!10,
frametitlebackgroundcolor=black!5,
frametitlerulewidth=2pt]}
{\end{mdframed}}

Expand Down Expand Up @@ -273,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 @@ -707,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 @@ -775,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 @@ -784,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 @@ -793,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 @@ -910,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 @@ -955,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 @@ -967,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 @@ -991,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-beginner.pdf
Binary file not shown.
Binary file modified handout-beginner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 26 additions & 25 deletions handout-beginner.tex
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
showtabs=false,
tabsize=2,
%
emph = { plot, scatter, imshow, bar, contourf, pie, subplots,
errorbar, boxplot, hist, title, xlabel, ylabel, suptitle },
emph = { plot, scatter, imshow, bar, contourf, pie, subplots, show, savefig,
errorbar, boxplot, hist, set_title, set_xlabel, set_ylabel, suptitle, },
emphstyle = {\ttfamily\bfseries}
}

Expand Down Expand Up @@ -89,8 +89,9 @@ \section*{\LARGE \rmfamily
%
\fbox{3} \textbf{Render}
\begin{lstlisting}
plt.plot(X, Y)
plt.show()
fig, ax = plt.subplots()
ax.plot(X, Y)
fig.show()
\end{lstlisting}
%
\fbox{4} \textbf{Observe} \medskip\\
Expand All @@ -106,7 +107,7 @@ \subsection*{\rmfamily Choose}
\begin{lstlisting}[belowskip=-\baselineskip]
X = np.random.uniform(0, 1, 100)
Y = np.random.uniform(0, 1, 100)
plt.scatter(X, Y)
ax.scatter(X, Y)
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{basic-scatter.pdf}}
\end{tabular}
Expand All @@ -115,7 +116,7 @@ \subsection*{\rmfamily Choose}
\begin{lstlisting}[belowskip=-\baselineskip]
X = np.arange(10)
Y = np.random.uniform(1, 10, 10)
plt.bar(X, Y)
ax.bar(X, Y)
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{basic-bar.pdf}}
\end{tabular}
Expand All @@ -124,7 +125,7 @@ \subsection*{\rmfamily Choose}
\begin{lstlisting}[belowskip=-\baselineskip]
Z = np.random.uniform(0, 1, (8,8)

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

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

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

plt.hist(Z)
ax.hist(Z)
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{advanced-hist.pdf}}
\end{tabular}
Expand All @@ -160,7 +161,7 @@ \subsection*{\rmfamily Choose}
\begin{lstlisting}[belowskip=-\baselineskip]
X = np.arange(5)
Y = np.random.uniform(0,1,5)
plt.errorbar(X, Y, Y/4)
ax.errorbar(X, Y, Y/4)
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{advanced-errorbar.pdf}}
\end{tabular}
Expand All @@ -169,7 +170,7 @@ \subsection*{\rmfamily Choose}
\begin{lstlisting}[belowskip=-\baselineskip]
Z = np.random.normal(0,1,(100,3))

plt.boxplot(Z)
ax.boxplot(Z)
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{advanced-boxplot.pdf}}
\end{tabular}
Expand All @@ -187,7 +188,7 @@ \subsection*{\rmfamily Tweak}
\begin{lstlisting}[belowskip=-\baselineskip]
X = np.linspace(0,10,100)
Y = np.sin(X)
plt.plot(X, Y, color="black")
ax.plot(X, Y, color="black")
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-color.pdf}}
\end{tabular}
Expand All @@ -196,7 +197,7 @@ \subsection*{\rmfamily Tweak}
\begin{lstlisting}[belowskip=-\baselineskip]
X = np.linspace(0,10,100)
Y = np.sin(X)
plt.plot(X, Y, linestyle="--")
ax.plot(X, Y, linestyle="--")
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-linestyle.pdf}}
\end{tabular}
Expand All @@ -205,7 +206,7 @@ \subsection*{\rmfamily Tweak}
\begin{lstlisting}[belowskip=-\baselineskip]
X = np.linspace(0,10,100)
Y = np.sin(X)
plt.plot(X, Y, linewidth=5)
ax.plot(X, Y, linewidth=5)
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-linewidth.pdf}}
\end{tabular}
Expand All @@ -214,7 +215,7 @@ \subsection*{\rmfamily Tweak}
\begin{lstlisting}[belowskip=-\baselineskip]
X = np.linspace(0,10,100)
Y = np.sin(X)
plt.plot(X, Y, marker="o")
ax.plot(X, Y, marker="o")
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-marker.pdf}}
\end{tabular}
Expand All @@ -232,7 +233,7 @@ \subsection*{\rmfamily Organize}
\begin{lstlisting}[belowskip=-\baselineskip]
X = np.linspace(0,10,100)
Y1, Y1 = np.sin(X), np.cos(X)
plt.plot(X, Y1, Y2)
ax.plot(X, Y1, Y2)
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-multi.pdf}}
\end{tabular}
Expand Down Expand Up @@ -261,18 +262,18 @@ \subsection*{\rmfamily Label \mdseries (everything)}
% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
\begin{lstlisting}[belowskip=-\baselineskip]
plt.plot(X, Y)
plt.suptitle(None)
plt.title("A Sine wave")
ax.plot(X, Y)
fig.suptitle(None)
ax.set_title("A Sine wave")
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-title.pdf}}
\end{tabular}
% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
\begin{lstlisting}[belowskip=-\baselineskip]
plt.plot(X, Y)
plt.ylabel(None)
plt.xlabel("Time")
ax.plot(X, Y)
ax.set_ylabel(None)
ax.set_xlabel("Time")
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{plot-xlabel.pdf}}
\end{tabular}
Expand All @@ -289,8 +290,8 @@ \subsection*{\rmfamily Explore}
\subsection*{\rmfamily Save \mdseries (bitmap or vector format)}
% -----------------------------------------------------------------------------
\begin{lstlisting}[belowskip=-\baselineskip]
plt.savefif("my-first-figure.png", dpi=300)
plt.savefig("my-first-figure.pdf")
fig.savefig("my-first-figure.png", dpi=300)
fig.savefig("my-first-figure.pdf")
\end{lstlisting}
%
\vfill
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