Skip to content

Commit c2ad430

Browse files
committed
Finished tips handout
1 parent ee64f0a commit c2ad430

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

handout-tips.tex

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,32 @@ \subsection*{\rmfamily Taking advantage of typography}
211211
\end{lstlisting}
212212
\includegraphics[width=\linewidth]{tip-font-family.pdf}
213213

214+
\subsection*{\rmfamily Getting rid of margins}
215+
Once your figure is finished, you can call {\ttfamily tight\_layout()}
216+
to remove white margins. If there are remaining margins, you can use
217+
the {\ttfamily pdfcrop} utility (comes with TeX live).
218+
219+
220+
\subsection*{\rmfamily Hatching}
221+
You can achieve nice visual effect with thick hatch patterns.
222+
223+
\begin{tabular}{@{}m{.774\linewidth}m{.216\linewidth}}
224+
\begin{lstlisting}[belowskip=-\baselineskip]
225+
cmap = plt.get_cmap("Oranges")
226+
plt.rcParams['hatch.color'] = cmap(0.2)
227+
plt.rcParams['hatch.linewidth'] = 8
228+
ax.bar(X, Y, color=cmap(0.6), hatch="/" )
229+
\end{lstlisting} &
230+
\raisebox{-0.75em}{\includegraphics[width=\linewidth]{tip-hatched.pdf}}
231+
\end{tabular}
232+
233+
234+
\subsection*{\rmfamily Read the documentation}
235+
236+
Matplotlib comes with an extensive documenation explaining every
237+
detals of each command and is generally accompanied by examples
238+
with. Together with the huge online gallery, this documenation is a
239+
gold-mine.
214240

215241
\vfill
216242
%

scripts/tip-hatched.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import numpy as np
2+
import matplotlib.pyplot as plt
3+
4+
cmap = plt.get_cmap("Oranges")
5+
color1, color2 = cmap(0.3), cmap(0.5)
6+
7+
plt.rcParams['hatch.color'] = color1
8+
plt.rcParams['hatch.linewidth'] = 8
9+
10+
fig = plt.figure(figsize=(2,2))
11+
ax = plt.subplot()
12+
np.random.seed(123)
13+
14+
x1,y1 = 3*np.arange(2), np.random.randint(25,50,2)
15+
x2,y2 = x1+1, np.random.randint(25,75,2)
16+
17+
ax.bar(x1, y1, color=color2)
18+
for i in range(len(x1)):
19+
plt.annotate("%d%%" % y1[i], (x1[i], y1[i]), xytext=(0,1),
20+
fontsize="x-small", color=color2,
21+
textcoords="offset points", va="bottom", ha="center")
22+
23+
ax.bar(x2, y2, color=color2, hatch="/" )
24+
for i in range(len(x2)):
25+
plt.annotate("%d%%" % y2[i], (x2[i], y2[i]), xytext=(0,1),
26+
fontsize="x-small", color=color2,
27+
textcoords="offset points", va="bottom", ha="center")
28+
29+
ax.set_yticks([])
30+
ax.set_xticks(0.5+np.arange(0,6,3))
31+
ax.set_xticklabels(["2018", "2019"])
32+
ax.tick_params('x', length=0, labelsize="small", which='major')
33+
34+
ax.spines['right'].set_visible(False)
35+
ax.spines['left'].set_visible(False)
36+
ax.spines['top'].set_visible(False)
37+
38+
plt.tight_layout()
39+
plt.savefig("../figures/tip-hatched.pdf")
40+
# plt.show()

0 commit comments

Comments
 (0)