36
36
%
37
37
emph = { plot, scatter, imshow, bar, contourf, pie, subplots, spines,
38
38
add_gridspec, add_subplot, set_xscale, set_minor_locator,
39
- set_minor_formatter, tick_params, fill_betweenx, text,
39
+ set_minor_formatter, tick_params, fill_betweenx, text, legend,
40
40
errorbar, boxplot, hist, title, xlabel, ylabel, suptitle },
41
41
emphstyle = {\ttfamily\bfseries }
42
42
}
@@ -78,7 +78,7 @@ \section*{\LARGE \rmfamily
78
78
79
79
\includegraphics [width=\linewidth ]{anatomy-cropped.pdf}
80
80
81
- \subsection* {Figure, axes \& spines }
81
+ \subsection* {\rmfamily Figure, axes \& spines }
82
82
83
83
% -----------------------------------------------------------------------------
84
84
\begin {tabular }{@{}m{.821\linewidth }m{.169\linewidth }}
@@ -113,7 +113,7 @@ \subsection*{Figure, axes \& spines}
113
113
114
114
115
115
% -----------------------------------------------------------------------------
116
- \subsection* {Ticks \& labels }
116
+ \subsection* {\rmfamily Ticks \& labels }
117
117
118
118
\ begin{lstlisting} [basicstyle=\ttfamily\small]
119
119
from mpl.ticker import MultipleLocator as ML
@@ -125,7 +125,7 @@ \subsection*{Ticks \& labels}
125
125
\includegraphics [width=\linewidth ]{tick-multiple-locator.pdf}
126
126
127
127
% -----------------------------------------------------------------------------
128
- \subsection* {Lines \& markers }
128
+ \subsection* {\rmfamily Lines \& markers }
129
129
130
130
\ begin{lstlisting}
131
131
X = np.linspace(0.1, 10*np.pi, 1000)
@@ -135,7 +135,7 @@ \subsection*{Lines \& markers}
135
135
\includegraphics [width=\linewidth ]{sine-marker.pdf}
136
136
137
137
% -----------------------------------------------------------------------------
138
- \subsection* {Scales \& Projections }
138
+ \subsection* {\rmfamily Scales \& Projections }
139
139
140
140
\ begin{lstlisting}
141
141
fig, ax = plt.subplots()
@@ -144,7 +144,7 @@ \subsection*{Scales \& Projections}
144
144
\end {lstlisting }
145
145
\includegraphics [width=\linewidth ]{sine-logscale.pdf}
146
146
147
- \subsection* {Text \& Ornaments }
147
+ \subsection* {\rmfamily Text \& Ornaments }
148
148
\ begin{lstlisting} []
149
149
ax.fill_betweenx([-1,1],[0],[2*np.pi])
150
150
ax.text(0, -1, r" Period $\Phi$")
@@ -153,12 +153,33 @@ \subsection*{Text \& Ornaments}
153
153
154
154
155
155
% -----------------------------------------------------------------------------
156
- \subsection* {Size \& DPI }
156
+ \subsection* {\rmfamily Legend }
157
+ \ begin{lstlisting} []
158
+ ax.plot(X, np.sin(X), "C0", label="Sine")
159
+ ax.plot(X, np.cos(X), "C1", label="Cosine")
160
+ ax.legend(bbox_to_anchor=(0,1,1,.1),ncol=2,
161
+ mode="expand", loc="lower left")
162
+ \end {lstlisting }
163
+ \includegraphics [width=\linewidth ]{sine-legend.pdf}
164
+
165
+
166
+ % -----------------------------------------------------------------------------
167
+ \subsection* {\rmfamily Colors }
168
+
169
+ Any color can be used but Matplotlib offers a set of colors:\\
170
+ \includegraphics [width=\linewidth ]{colors-cycle.pdf} \smallskip
171
+ \includegraphics [width=\linewidth ]{colors-grey.pdf}\\
172
+ As well as nice colormaps (viridis an magma):\\
173
+ \includegraphics [width=\linewidth ]{colormap-viridis.pdf} \smallskip
174
+ \includegraphics [width=\linewidth ]{colormap-magma.pdf} \medskip
175
+
176
+ % -----------------------------------------------------------------------------
177
+ \subsection* {\rmfamily Size \& DPI }
157
178
158
179
Consider a square figure to be included in a two-columns A4 paper with
159
180
2cm margins on each side and a column separation of 1cm. The width of
160
181
a figure is (21 - 2*2 - 1)/2 = 8cm. One inch being 2.54cm, figure size
161
- should be 3.15$ \times $ 3.15 inches .
182
+ should be 3.15$ \times $ 3.15 in .
162
183
\ begin{lstlisting} []
163
184
fig = plt.figure(figsize=(3.15,3.15), dpi=50)
164
185
plt.savefig("figure.pdf", dpi=600)
0 commit comments