Skip to content

Commit eeb1719

Browse files
committed
Started second page
1 parent 02da911 commit eeb1719

File tree

4 files changed

+417
-13
lines changed

4 files changed

+417
-13
lines changed

cheatsheet-basic.tex

Lines changed: 149 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -659,22 +659,32 @@
659659
\API{https://matplotlib.org/tutorials/introductory/customizing.html}}
660660
\setlength{\fboxsep}{0pt}%
661661
\setlength{\fboxrule}{.25pt}%
662-
{\ttfamily plt.style.use(\textbf{style})\smallskip}\\
663-
\fbox{\includegraphics[width=.24\columnwidth]{style-default.pdf}}
664-
\fbox{\includegraphics[width=.24\columnwidth]{style-classic.pdf}}
665-
\fbox{\includegraphics[width=.24\columnwidth]{style-grayscale.pdf}}
666-
\fbox{\includegraphics[width=.24\columnwidth]{style-ggplot.pdf}}
667-
\fbox{\includegraphics[width=.24\columnwidth]{style-seaborn.pdf}}
668-
\fbox{\includegraphics[width=.24\columnwidth]{style-fast.pdf}}
669-
\fbox{\includegraphics[width=.24\columnwidth]{style-bmh.pdf}}
670-
\fbox{\includegraphics[width=.24\columnwidth]{style-Solarize_Light2.pdf}}
662+
{\ttfamily plt.style.use(\textbf{style})\medskip}\\
663+
\fbox{\includegraphics[width=.32\columnwidth]{style-default.pdf}}
664+
\fbox{\includegraphics[width=.32\columnwidth]{style-classic.pdf}}
665+
\fbox{\includegraphics[width=.32\columnwidth]{style-grayscale.pdf}}
666+
\fbox{\includegraphics[width=.32\columnwidth]{style-ggplot.pdf}}
667+
\fbox{\includegraphics[width=.32\columnwidth]{style-seaborn.pdf}}
668+
\fbox{\includegraphics[width=.32\columnwidth]{style-fast.pdf}}
669+
\fbox{\includegraphics[width=.32\columnwidth]{style-bmh.pdf}}
670+
\fbox{\includegraphics[width=.32\columnwidth]{style-Solarize_Light2.pdf}}
671+
\fbox{\includegraphics[width=.32\columnwidth]{style-seaborn-notebook.pdf}}
672+
%% \fbox{\includegraphics[width=.24\columnwidth]{style-default.pdf}}
673+
%% \fbox{\includegraphics[width=.24\columnwidth]{style-classic.pdf}}
674+
%% \fbox{\includegraphics[width=.24\columnwidth]{style-grayscale.pdf}}
675+
%% \fbox{\includegraphics[width=.24\columnwidth]{style-ggplot.pdf}}
676+
%% \fbox{\includegraphics[width=.24\columnwidth]{style-seaborn.pdf}}
677+
%% \fbox{\includegraphics[width=.24\columnwidth]{style-fast.pdf}}
678+
%% \fbox{\includegraphics[width=.24\columnwidth]{style-bmh.pdf}}
679+
%% \fbox{\includegraphics[width=.24\columnwidth]{style-Solarize_Light2.pdf}}
671680
\end{myboxed}
672681
%
673682
\vspace{\fill}
674683
%
675684
\begin{myboxed}{Quick reminder}
676685
{\ttfamily
677-
ax.\textbf{grid}(), ax.patch.\textbf{set\_alpha}(0)\\
686+
ax.\textbf{grid}()\\
687+
ax.patch.\textbf{set\_alpha}(0)\\
678688
ax.\textbf{set\_[xy]lim}(vmin, vmax)\\
679689
ax.\textbf{set\_[xy]label}(label)\\
680690
ax.\textbf{set\_[xy]ticks}(list)\\
@@ -736,12 +746,138 @@
736746
8. Avoid “Chartjunk”\\
737747
9. Message Trumps Beauty\\
738748
10. Get the Right Tool
749+
\end{myboxed}
750+
\end{multicols*}
751+
752+
\begin{multicols*}{5}
753+
\begin{myboxed}{Axes adjustements\hfill
754+
\API{https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots_adjust.html}}
755+
plt.\textbf{subplot\_adjust}( … )\\
756+
757+
\includegraphics[width=\columnwidth]{adjustments.pdf}
739758
\end{myboxed}
740-
759+
%
760+
\vspace{\fill}
761+
%
762+
\begin{myboxed}{Extent \& origin \hfill
763+
\API{https://matplotlib.org/tutorials/intermediate/imshow_extent.html} }
764+
plt.\textbf{imshow}( extent=…, origin=… )\\
741765

766+
\includegraphics[width=\columnwidth]{extents.pdf}
767+
\end{myboxed}
768+
%
769+
\vspace{\fill}
770+
%
771+
\begin{myboxed}{Text aligmnents \hfill
772+
\API{https://matplotlib.org/tutorials/text/text_props.html} }
773+
plt.\textbf{text}( …, ha=… , va=…, … )\\
742774

743-
744-
775+
\includegraphics[width=\columnwidth]{text-alignments.pdf}
776+
\end{myboxed}
777+
%
778+
\vspace{\fill}
779+
%
780+
\begin{myboxed}{Text parameters \hfill
781+
\API{https://matplotlib.org/tutorials/text/text_props.html}}
782+
plt.\textbf{text}( …, family=… , size=…, weight = …)\\
783+
plt.\textbf{text}( …, fontproperties = … )\\
784+
785+
\includegraphics[width=\columnwidth]{fonts.pdf}
786+
\end{myboxed}
787+
788+
789+
\begin{myboxed}{Uniform colormaps}
790+
\begin{tabular}{@{}p{0.7\columnwidth}p{0.25\columnwidth}@{}}
791+
\scriptsize \rule{0pt}{1.25em}\noindent
792+
\colormap{viridis}
793+
\colormap{plasma}
794+
\colormap{inferno}
795+
\colormap{magma}
796+
\colormap{cividis}
797+
\end{tabular}
798+
\end{myboxed}
799+
%
800+
\vspace{\fill}
801+
%
802+
\begin{myboxed}{Sequential colormaps}
803+
\begin{tabular}{@{}p{0.7\columnwidth}p{0.25\columnwidth}@{}}
804+
\scriptsize \rule{0pt}{1.25em}\noindent
805+
\colormap{Greys}
806+
\colormap{Purples}
807+
\colormap{Blues}
808+
\colormap{Greens}
809+
\colormap{Oranges}
810+
\colormap{Reds}
811+
\colormap{YlOrBr}
812+
\colormap{YlOrRd}
813+
\colormap{OrRd}
814+
\colormap{PuRd}
815+
\colormap{RdPu}
816+
\colormap{BuPu}
817+
\colormap{GnBu}
818+
\colormap{PuBu}
819+
\colormap{YlGnBu}
820+
\colormap{PuBuGn}
821+
\colormap{BuGn}
822+
\colormap{YlGn}
823+
\end{tabular}
824+
\end{myboxed}
825+
%
826+
\vspace{\fill}
827+
%
828+
\begin{myboxed}{Diverging colormaps}
829+
\begin{tabular}{@{}p{0.7\columnwidth}p{0.25\columnwidth}@{}}
830+
\scriptsize \rule{0pt}{1.25em}\noindent
831+
\colormap{PiYG}
832+
\colormap{PRGn}
833+
\colormap{BrBG}
834+
\colormap{PuOr}
835+
\colormap{RdGy}
836+
\colormap{RdBu}
837+
\colormap{RdYlBu}
838+
\colormap{RdYlGn}
839+
\colormap{Spectral}
840+
\colormap{coolwarm}
841+
\colormap{bwr}
842+
\colormap{seismic}
843+
\end{tabular}
844+
\end{myboxed}
845+
%
846+
\vspace{\fill}
847+
%
848+
\begin{myboxed}{Qualitative colormaps}
849+
\begin{tabular}{@{}p{0.7\columnwidth}p{0.25\columnwidth}@{}}
850+
\scriptsize \rule{0pt}{1.25em}\noindent
851+
\colormap{Pastel1}
852+
\colormap{Pastel2}
853+
\colormap{Paired}
854+
\colormap{Accent}
855+
\colormap{Dark2}
856+
\colormap{Set1}
857+
\colormap{Set2}
858+
\colormap{Set3}
859+
\colormap{tab10}
860+
\colormap{tab20}
861+
\colormap{tab20b}
862+
\colormap{tab20c}
863+
\end{tabular}
864+
\end{myboxed}
865+
%
866+
\vspace{\fill}
867+
%
868+
\begin{myboxed}{Miscellaneous colormaps}
869+
\begin{tabular}{@{}p{0.7\columnwidth}p{0.25\columnwidth}@{}}
870+
\scriptsize \rule{0pt}{1.25em}\noindent
871+
\colormap{terrain}
872+
\colormap{ocean}
873+
\colormap{cubehelix}
874+
\colormap{rainbow}
875+
\colormap{twilight}
876+
\end{tabular}
877+
\end{myboxed}
878+
745879
\end{multicols*}
880+
881+
746882
\end{document}
747883

scripts/adjustements.py

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
# -----------------------------------------------------------------------------
2+
# Matplotlib cheat sheet
3+
# Released under the BSD License
4+
# -----------------------------------------------------------------------------
5+
6+
import numpy as np
7+
import matplotlib.pyplot as plt
8+
import matplotlib.patches as mpatches
9+
from matplotlib.collections import PatchCollection
10+
11+
12+
fig = plt.figure(figsize=(4.25, 4.25 * 95/115))
13+
ax = fig.add_axes([0,0,1,1], frameon=False, aspect=1,
14+
xlim=(0-5,100+10), ylim=(-10,80+5), xticks=[], yticks=[])
15+
16+
17+
box = mpatches.FancyBboxPatch(
18+
(0,0), 100, 83, mpatches.BoxStyle("Round", pad=0, rounding_size=2),
19+
linewidth=1., facecolor="0.9", edgecolor="black")
20+
ax.add_artist(box)
21+
22+
box = mpatches.FancyBboxPatch(
23+
(0,0), 100, 75, mpatches.BoxStyle("Round", pad=0, rounding_size=0),
24+
linewidth=1., facecolor="white", edgecolor="black")
25+
ax.add_artist(box)
26+
27+
28+
box = mpatches.Rectangle(
29+
(5,5), 45, 30, zorder=10,
30+
linewidth=1.0, facecolor="white", edgecolor="black")
31+
ax.add_artist(box)
32+
33+
box = mpatches.Rectangle(
34+
(5,40), 45, 30, zorder=10,
35+
linewidth=1.0, facecolor="white", edgecolor="black")
36+
ax.add_artist(box)
37+
38+
box = mpatches.Rectangle(
39+
(55,5), 40, 65, zorder=10,
40+
linewidth=1.0, facecolor="white", edgecolor="black")
41+
ax.add_artist(box)
42+
43+
# Window button
44+
X, Y = [5,10,15], [79,79,79]
45+
plt.scatter(X, Y, s=75, zorder=10,
46+
edgecolor="black", facecolor="white", linewidth=1)
47+
48+
49+
# Window size extension
50+
X, Y = [0, 0], [0, -8]
51+
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
52+
53+
X, Y = [100, 100], [0, -8]
54+
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
55+
56+
X, Y = [100, 108], [0, 0]
57+
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
58+
59+
X, Y = [100, 108], [75, 75]
60+
plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False)
61+
62+
63+
def ext_arrow(p0,p1,p2,p3):
64+
p0, p1 = np.asarray(p0), np.asarray(p1)
65+
p2, p3 = np.asarray(p2), np.asarray(p3)
66+
ax.arrow(*p0, *(p1-p0), zorder=20, linewidth=0,
67+
length_includes_head=True, width=.4,
68+
head_width=2, head_length=2, color="black")
69+
ax.arrow(*p3, *(p2-p3), zorder=20, linewidth=0,
70+
length_includes_head=True, width=.4,
71+
head_width=2, head_length=2, color="black")
72+
plt.plot([p1[0],p2[0]], [p1[1],p2[1]], linewidth=.9, color="black")
73+
74+
def int_arrow(p0,p1):
75+
p0, p1 = np.asarray(p0), np.asarray(p1)
76+
ax.arrow(*((p0+p1)/2), *((p1-p0)/2), zorder=20, linewidth=0,
77+
length_includes_head=True, width=.4,
78+
head_width=2, head_length=2, color="black")
79+
ax.arrow(*((p0+p1)/2), *(-(p1-p0)/2), zorder=20, linewidth=0,
80+
length_includes_head=True, width=.4,
81+
head_width=2, head_length=2, color="black")
82+
83+
84+
85+
x = 0
86+
y = 10
87+
ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) )
88+
ax.text(x+9.5, y, "left", ha="left", va="center", size="x-small", zorder=20)
89+
90+
x += 50
91+
ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) )
92+
ax.text(x-4.5, y, "wspace", ha="right", va="center", size="x-small", zorder=20)
93+
94+
x += 45
95+
ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) )
96+
ax.text(x-4.5, y, "right", ha="right", va="center", size="x-small", zorder=20)
97+
98+
y = 0
99+
x = 25
100+
ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) )
101+
ax.text(x, y+9.5, "bottom", ha="center", va="bottom", size="x-small", zorder=20)
102+
103+
y += 35
104+
ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) )
105+
ax.text(x, y-4.5, "hspace", ha="center", va="top", size="x-small", zorder=20)
106+
107+
y += 35
108+
ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) )
109+
ax.text(x, y-4.5, "top", ha="center", va="top", size="x-small", zorder=20)
110+
111+
int_arrow((0,-5), (100,-5))
112+
ax.text(50, -5, "figure width", backgroundcolor="white", zorder=30,
113+
ha="center", va="center", size="x-small")
114+
115+
int_arrow((105,0), (105,75))
116+
ax.text(105, 75/2, "figure height", backgroundcolor="white", zorder=30,
117+
rotation = "vertical", ha="center", va="center", size="x-small")
118+
119+
int_arrow((55,62.5), (95,62.5))
120+
ax.text(75, 62.5, "axes width", backgroundcolor="white", zorder=30,
121+
ha="center", va="center", size="x-small")
122+
123+
int_arrow((62.5,5), (62.5,70))
124+
ax.text(62.5, 35, "axes height", backgroundcolor="white", zorder=30,
125+
rotation = "vertical", ha="center", va="center", size="x-small")
126+
127+
128+
plt.savefig("../figures/adjustments.pdf")
129+
# plt.show()

scripts/extents.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# -----------------------------------------------------------------------------
2+
# Matplotlib cheat sheet
3+
# Released under the BSD License
4+
# -----------------------------------------------------------------------------
5+
6+
# Scripts to generate all the basic plots
7+
import numpy as np
8+
import matplotlib as mpl
9+
import matplotlib.pyplot as plt
10+
11+
Z = np.arange(5*5).reshape(5,5)
12+
13+
fig = plt.figure(figsize=(8,5))
14+
15+
ax = fig.add_subplot(2,2,1)
16+
ax.imshow(Z, extent=[0,10,0,5], interpolation="nearest", origin="upper")
17+
ax.set_xlim(-1, 11), ax.set_xticks([])
18+
ax.set_ylim(-1, 6), ax.set_yticks([0,5])
19+
ax.text(1, 4.5, "(0,0)", ha="center", va="center", color="white", size="large")
20+
ax.text(9, 0.5, "(4,4)", ha="center", va="center", color="black", size="large")
21+
ax.text(5.0, 5.5, 'origin="upper"',
22+
ha="center", va="center", color="black", size="large")
23+
ax.text(5.0, -0.5, "extent=[0,10,0,5]",
24+
ha="center", va="center", color="black", size="large")
25+
26+
ax = fig.add_subplot(2,2,3)
27+
ax.imshow(Z, extent=[0,10,0,5], interpolation="nearest", origin="lower")
28+
ax.set_xlim(-1, 11), ax.set_xticks([0,10])
29+
ax.set_ylim(-1, 6), ax.set_yticks([0,5])
30+
ax.text(1, 0.5, "(0,0)", ha="center", va="center", color="white", size="large")
31+
ax.text(9, 4.5, "(4,4)", ha="center", va="center", color="black", size="large")
32+
33+
ax.text(5.0, 5.5, 'origin="lower"',
34+
ha="center", va="center", color="black", size="large")
35+
ax.text(5.0, -0.5, "extent=[0,10,0,5]",
36+
ha="center", va="center", color="black", size="large")
37+
38+
39+
ax = fig.add_subplot(2,2,4)
40+
ax.imshow(Z, extent=[10,0,0,5], interpolation="nearest", origin="lower")
41+
ax.set_xlim(-1, 11), ax.set_xticks([0,10])
42+
ax.set_ylim(-1, 6), ax.set_yticks([])
43+
ax.text(9, 0.5, "(0,0)", ha="center", va="center", color="white", size="large")
44+
ax.text(1, 4.5, "(4,4)", ha="center", va="center", color="black", size="large")
45+
ax.text(5.0, 5.5, 'origin="lower"',
46+
ha="center", va="center", color="black", size="large")
47+
ax.text(5.0, -0.5, "extent=[10,0,0,5]",
48+
ha="center", va="center", color="black", size="large")
49+
plt.tight_layout()
50+
51+
52+
ax = fig.add_subplot(2,2,2)
53+
ax.imshow(Z, extent=[10,0,0,5], interpolation="nearest", origin="upper")
54+
ax.set_xlim(-1, 11), ax.set_xticks([])
55+
ax.set_ylim(-1, 6), ax.set_yticks([])
56+
ax.text(9, 4.5, "(0,0)", ha="center", va="center", color="white", size="large")
57+
ax.text(1, 0.5, "(4,4)", ha="center", va="center", color="black", size="large")
58+
ax.text(5.0, 5.5, 'origin="lower"',
59+
ha="center", va="center", color="black", size="large")
60+
ax.text(5.0, -0.5, "extent=[10,0,0,5]",
61+
ha="center", va="center", color="black", size="large")
62+
plt.tight_layout()
63+
64+
65+
plt.savefig("../figures/extents.pdf", dpi=600)
66+
plt.show()
67+
68+
69+

0 commit comments

Comments
 (0)