Skip to content
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

Fix minor typos #149

Merged
merged 3 commits into from
Feb 6, 2024
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
64 changes: 32 additions & 32 deletions cheatsheets.tex
Original file line number Diff line number Diff line change
Expand Up @@ -301,13 +301,13 @@
% --- Layout ---------------------------------------------------------------
\begin{myboxed}{Subplots layout \hfill
\API{https://matplotlib.org/tutorials/intermediate/gridspec.html} }
\plot{layout-subplot.pdf}{\textbf{subplot[s]}(rows,cols,…)}
\plot{layout-subplot.pdf}{\textbf{subplot[s]}(rows, cols, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html}
{\ttfamily fig, axs = plt.subplots(3, 3)}
{}
\plot{layout-gridspec.pdf}{G = \textbf{gridspec}(rows,cols,…)}
\plot{layout-gridspec.pdf}{G = \textbf{gridspec}(rows,cols, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.gridspec.GridSpec.html}
{\ttfamily ax = G[0,:]}{}
{\ttfamily ax = G[0, :]}{}
\plot{layout-inset.pdf}{ax.\textbf{inset\_axes}(extent)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.inset_axes.html}
{}{}
Expand Down Expand Up @@ -338,7 +338,7 @@

% --- Basic plots -----------------------------------------------------------
\begin{myboxed}{Basic plots}
\plot{basic-plot.pdf}{\textbf{plot}([X],Y,[fmt],…)}
\plot{basic-plot.pdf}{\textbf{plot}([X], Y, [fmt], …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html}
{\optional{X},
\mandatory{Y},
Expand All @@ -347,7 +347,7 @@
\optional{marker},
\optional{linestyle}}
{}
\plot{basic-scatter.pdf}{\textbf{scatter}(X,Y,…)}
\plot{basic-scatter.pdf}{\textbf{scatter}(X, Y, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html}
{\mandatory{X},
\mandatory{Y},
Expand All @@ -356,23 +356,23 @@
\optional{marker},
\optional{cmap}}
{}
\plot{basic-bar.pdf}{\textbf{bar[h]}(x,height,…)}
\plot{basic-bar.pdf}{\textbf{bar[h]}(x, height, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.bar.html}
{ \mandatory{x},
\mandatory{height},
\optional{width},
\optional{bottom},
\optional{align},
\optional{color} }{}
\plot{basic-imshow.pdf}{\textbf{imshow}(Z,…)}
\plot{basic-imshow.pdf}{\textbf{imshow}(Z, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html}
{ \mandatory{Z},
\optional{cmap},
\optional{interpolation},
\optional{extent},
\optional{origin} }
{}
\plot{basic-contour.pdf}{\textbf{contour[f]}([X],[Y],Z,…)}
\plot{basic-contour.pdf}{\textbf{contour[f]}([X], [Y], Z, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html}
{ \optional{X},
\optional{Y},
Expand All @@ -382,7 +382,7 @@
\optional{extent},
\optional{origin} }
{}
\plot{basic-pcolormesh.pdf}{\textbf{pcolormesh}([X],[Y],Z,…)}
\plot{basic-pcolormesh.pdf}{\textbf{pcolormesh}([X], [Y], Z, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pcolormesh.html}
{ \optional{X},
\optional{Y},
Expand All @@ -391,7 +391,7 @@
\optional{vmax},
\optional{cmap}}
{}
\plot{basic-quiver.pdf}{\textbf{quiver}([X],[Y],U,V,…)}
\plot{basic-quiver.pdf}{\textbf{quiver}([X], [Y], U, V, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.quiver.html}
{ \optional{X},
\optional{Y},
Expand All @@ -401,15 +401,15 @@
\optional{units},
\optional{angles} }
{}
\plot{basic-pie.pdf}{\textbf{pie}(X,…)}
\plot{basic-pie.pdf}{\textbf{pie}(X, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.pie.html}
{\mandatory{Z},
\optional{explode},
\optional{labels},
\optional{colors},
\optional{radius}}
{}
\plot{basic-text.pdf}{\textbf{text}(x,y,text,…)}
\plot{basic-text.pdf}{\textbf{text}(x, y, text, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.text.html}
{\mandatory{x},
\mandatory{y},
Expand All @@ -432,7 +432,7 @@
\vspace{\fill}
% --- Advanced plots --------------------------------------------------------
\begin{myboxed}{Advanced plots}
\plot{advanced-step.pdf}{\textbf{step}(X,Y,[fmt],…)}
\plot{advanced-step.pdf}{\textbf{step}(X, Y, [fmt], …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.step.html}
{\mandatory{X},
\mandatory{Y},
Expand All @@ -441,15 +441,15 @@
\optional{marker},
\optional{where} }
{}
\plot{advanced-boxplot.pdf}{\textbf{boxplot}(X,…)}
\plot{advanced-boxplot.pdf}{\textbf{boxplot}(X, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.boxplot.html}
{ \mandatory{X},
\optional{notch},
\optional{sym},
\optional{bootstrap},
\optional{widths} }
{}
\plot{advanced-errorbar.pdf}{\textbf{errorbar}(X,Y,xerr,yerr,…)}
\plot{advanced-errorbar.pdf}{\textbf{errorbar}(X,Y,xerr,yerr, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.errorbar.html}
{ \mandatory{X},
\mandatory{Y},
Expand All @@ -465,14 +465,14 @@
\optional{density},
\optional{weights}}
{}
\plot{advanced-violin.pdf}{\textbf{violinplot}(D,…)}
\plot{advanced-violin.pdf}{\textbf{violinplot}(D, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.violinplot.html}
{\mandatory{D},
\optional{positions},
\optional{widths},
\optional{vert} }
{}
\plot{advanced-barbs.pdf}{\textbf{barbs}([X],[Y], U, V, …)}
\plot{advanced-barbs.pdf}{\textbf{barbs}([X], [Y], U, V, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.barbs.html}
{ \optional{X},
\optional{Y},
Expand All @@ -483,13 +483,13 @@
\optional{pivot},
\optional{sizes} }
{}
\plot{advanced-event.pdf}{\textbf{eventplot}(positions,…)}
\plot{advanced-event.pdf}{\textbf{eventplot}(positions, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.eventplot.html}
{\mandatory{positions},
\optional{orientation},
\optional{lineoffsets} }
{}
\plot{advanced-hexbin.pdf}{\textbf{hexbin}(X,Y,C,…)}
\plot{advanced-hexbin.pdf}{\textbf{hexbin}(X, Y, C, …)}
{https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hexbin.html}
{\mandatory{X},
\mandatory{Y},
Expand All @@ -503,7 +503,7 @@
% --- Scale ---------------------------------------------------------------
\begin{myboxed}{Scales \hfill
\API{https://matplotlib.org/stable/api/scale_api.html}}
{\ttfamily ax.\textbf{set\_[xy]scale}(scale,…)}
{\ttfamily ax.\textbf{set\_[xy]scale}(scale, …)}
\smallskip
\scale{scale-linear.pdf}{\textbf{linear}}{any values}
\scale{scale-log.pdf}{\textbf{log}}{values > 0}
Expand All @@ -516,7 +516,7 @@
% --- Projections -----------------------------------------------------------
\begin{myboxed}{Projections \hfill
\API{https://matplotlib.org/stable/api/projections_api.html}}
{\ttfamily \textbf{subplot}(…,projection=p)}
{\ttfamily \textbf{subplot}(…, projection=p)}
\smallskip
\scale{projection-polar.pdf}{p='polar'}{}
\scale{projection-3d.pdf}
Expand Down Expand Up @@ -906,7 +906,7 @@

\begin{myboxed}{Legend placement}
\includegraphics[width=\columnwidth]{legend-placement.pdf}
ax.\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 All @@ -919,12 +919,12 @@
\begin{tabular}{@{}p{0.495\columnwidth}
p{0.495\columnwidth}@{}}
\scriptsize \rule{0pt}{1.25em}\noindent
\tiny A: upper right / {\ttfamily (-0.1,0.9)} & \tiny B: center right / {\ttfamily (-0.1,0.5)}\\
\tiny C: lower right / {\ttfamily (-0.1,0.1)} & \tiny D: upper left / {\ttfamily (0.1,-0.1)}\\
\tiny E: upper center / {\ttfamily (0.5,-0.1)} & \tiny F: upper right / {\ttfamily (0.9,-0.1)}\\
\tiny G: lower left / {\ttfamily (1.1,0.1)} & \tiny H: center left / {\ttfamily (1.1,0.5)}\\
\tiny I: upper left / {\ttfamily (1.1,0.9)} & \tiny J: lower right / {\ttfamily (0.9,1.1)}\\
\tiny K: lower center / {\ttfamily (0.5,1.1)} & \tiny L: lower left / {\ttfamily (0.1,1.1)}
\tiny A: upper right / {\ttfamily (-0.1, 0.9)} & \tiny B: center right / {\ttfamily (-0.1, 0.5)}\\
\tiny C: lower right / {\ttfamily (-0.1, 0.1)} & \tiny D: upper left / {\ttfamily (0.1, -0.1)}\\
\tiny E: upper center / {\ttfamily (0.5, -0.1)} & \tiny F: upper right / {\ttfamily (0.9, -0.1)}\\
\tiny G: lower left / {\ttfamily (1.1, 0.1)} & \tiny H: center left / {\ttfamily (1.1, 0.5)}\\
\tiny I: upper left / {\ttfamily (1.1, 0.9)} & \tiny J: lower right / {\ttfamily (0.9, 1.1)}\\
\tiny K: lower center / {\ttfamily (0.5, 1.1)} & \tiny L: lower left / {\ttfamily (0.1, 1.1)}
\end{tabular}
\end{myboxed}
%
Expand Down Expand Up @@ -1000,12 +1000,12 @@
plot(X, Y, marker="o", ls="") \hfill fast%
\vskip.5\baselineskip
%
\textcolor{red}{for i in range(n): plot(X[i]) \hfill slow}\\
plot(sum([x+[None] for x in X],[])) \hfill fast%
\textcolor{red}{for i in range(n): plot(i, X[i], "o") \hfill slow}\\
plot(X, marker="o", ls="") \hfill fast%
\vskip.5\baselineskip
%
\textcolor{red}{cla(), imshow(…), canvas.draw() \hfill slow}\\
im.set\_data(…), canvas.draw() \hfill fast%
\textcolor{red}{cla(); imshow(…); canvas.draw() \hfill slow}\\
im.set\_data(…); canvas.draw() \hfill fast%
\vskip.1\baselineskip
}
\end{myboxed}
Expand Down
16 changes: 8 additions & 8 deletions handout-beginner.tex
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ \section*{\LARGE \rmfamily
%
\fbox{2} \textbf{Prepare}
\begin{lstlisting}
X = np.linspace(0, 4*np.pi, 1000)
X = np.linspace(0, 10*np.pi, 1000)
Y = np.sin(X)
\end{lstlisting}
%
Expand Down Expand Up @@ -123,7 +123,7 @@ \subsection*{\rmfamily Choose}
% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
\begin{lstlisting}[belowskip=-\baselineskip]
Z = np.random.uniform(0, 1, (8,8))
Z = np.random.uniform(0, 1, (8, 8))

ax.imshow(Z)
\end{lstlisting}
Expand All @@ -132,7 +132,7 @@ \subsection*{\rmfamily Choose}
% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
\begin{lstlisting}[belowskip=-\baselineskip]
Z = np.random.uniform(0, 1, (8,8))
Z = np.random.uniform(0, 1, (8, 8))

ax.contourf(Z)
\end{lstlisting}
Expand Down Expand Up @@ -168,7 +168,7 @@ \subsection*{\rmfamily Choose}
% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
\begin{lstlisting}[belowskip=-\baselineskip]
Z = np.random.normal(0, 1, (100,3))
Z = np.random.normal(0, 1, (100, 3))

ax.boxplot(Z)
\end{lstlisting}
Expand Down Expand Up @@ -225,8 +225,8 @@ \subsection*{\rmfamily Tweak}
\subsection*{\rmfamily Organize}
% -----------------------------------------------------------------------------

You can plot several data on the the same figure, but you can also
split a figure in several subplots (named {\em Axes}): \medskip
You can plot several data on the same figure, but you can also split a figure
in several subplots (named {\em Axes}): \medskip

% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
Expand All @@ -240,7 +240,7 @@ \subsection*{\rmfamily Organize}
% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
\begin{lstlisting}[belowskip=-\baselineskip]
fig, (ax1, ax2) = plt.subplots(2,1)
fig, (ax1, ax2) = plt.subplots(2, 1)
ax1.plot(X, Y1, color="C1")
ax2.plot(X, Y2, color="C0")
\end{lstlisting}
Expand All @@ -249,7 +249,7 @@ \subsection*{\rmfamily Organize}
% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
\begin{lstlisting}[belowskip=-\baselineskip]
fig, (ax1, ax2) = plt.subplots(1,2)
fig, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot(Y1, X, color="C1")
ax2.plot(Y2, X, color="C0")
\end{lstlisting}
Expand Down
32 changes: 16 additions & 16 deletions handout-intermediate.tex
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ \subsection*{\rmfamily Figure, axes \& spines}
% -----------------------------------------------------------------------------
\begin{tabular}{@{}m{.821\linewidth}m{.169\linewidth}}
\begin{lstlisting}[belowskip=-\baselineskip]
fig, axs = plt.subplots(3,3)
axs[0,0].set_facecolor("#ddddff")
axs[2,2].set_facecolor("#ffffdd")
fig, axs = plt.subplots(3, 3)
axs[0, 0].set_facecolor("#ddddff")
axs[2, 2].set_facecolor("#ffffdd")
\end{lstlisting}
& \raisebox{-0.75em}{\includegraphics[width=\linewidth]{layout-subplot-color.pdf}}
\end{tabular}
Expand Down Expand Up @@ -130,7 +130,7 @@ \subsection*{\rmfamily Lines \& markers}
\begin{lstlisting}
X = np.linspace(0.1, 10*np.pi, 1000)
Y = np.sin(X)
ax.plot(X, Y, "C1o:", markevery=25, mec="1.0")
ax.plot(X, Y, "C1o:", markevery=50, mec="1.0")
\end{lstlisting}
\includegraphics[width=\linewidth]{sine-marker.pdf}

Expand All @@ -140,13 +140,13 @@ \subsection*{\rmfamily Scales \& projections}
\begin{lstlisting}
fig, ax = plt.subplots()
ax.set_xscale("log")
ax.plot(X, Y, "C1o-", markevery=25, mec="1.0")
ax.plot(X, Y, "C1o-", markevery=50, mec="1.0")
\end{lstlisting}
\includegraphics[width=\linewidth]{sine-logscale.pdf}

\subsection*{\rmfamily Text \& ornaments}
\begin{lstlisting}[]
ax.fill_betweenx([-1,1],[0],[2*np.pi])
ax.fill_betweenx([-1, 1], [0], [2*np.pi])
ax.text(0, -1, r" Period $\Phi$")
\end{lstlisting}
\includegraphics[width=\linewidth]{sine-period.pdf}
Expand All @@ -157,17 +157,17 @@ \subsection*{\rmfamily Legend}
\begin{lstlisting}[]
ax.plot(X, np.sin(X), "C0", label="Sine")
ax.plot(X, np.cos(X), "C1", label="Cosine")
ax.legend(bbox_to_anchor=(0,1,1,.1),ncol=2,
mode="expand", loc="lower left")
ax.legend(bbox_to_anchor=(0,1,1,.1), ncol=2,
mode="expand", loc="lower left")
\end{lstlisting}
\includegraphics[width=\linewidth]{sine-legend.pdf}

% -----------------------------------------------------------------------------
\subsection*{\rmfamily Annotation}
\begin{lstlisting}[]
ax.annotate("A", (X[250],Y[250]),(X[250],-1),
ha="center", va="center",arrowprops =
{"arrowstyle" : "->", "color": "C1"})
ax.annotate("A", (X[250],Y[250]), (X[250],-1),
ha="center", va="center", arrowprops={
"arrowstyle": "->", "color": "C1"})
\end{lstlisting}
\includegraphics[width=\linewidth]{sine-annotate.pdf}

Expand All @@ -185,12 +185,12 @@ \subsection*{\rmfamily Colors}
\vspace{-1em}
\subsection*{\rmfamily Size \& DPI}

Consider a square figure to be included in a two-columns A4 paper with
2cm margins on each side and a column separation of 1cm. The width of
a figure is (21 - 2*2 - 1)/2 = 8cm. One inch being 2.54cm, figure size
should be 3.15$\times$3.15 in.
Consider a square figure to be included in a two-column A4 paper with
2\,cm margins on each side and a column separation of 1\,cm. The width of
a figure is (21 - 2*2 - 1)/2 = 8\,cm. One inch being 2.54\,cm, figure size
should be 3.15$\times$3.15\,in.
\begin{lstlisting}[]
fig = plt.figure(figsize=(3.15,3.15), dpi=50)
fig = plt.figure(figsize=(3.15, 3.15), dpi=50)
plt.savefig("figure.pdf", dpi=600)
\end{lstlisting}

Expand Down
Loading
Loading