Skip to content

Commit 7b8c31b

Browse files
committed
Improve formatting of "Anatomy of a figure"
- Adapt margins - Reduce figure border width (still thick but not massive) - fontfamily: make code monospace - slightly move annotations to better places
1 parent 03f153e commit 7b8c31b

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

examples/showcase/anatomy.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
Y3 = np.random.uniform(Y1, Y2, len(X))
2727

2828
fig = plt.figure(figsize=(8, 8))
29-
marg = 0.15
30-
ax = fig.add_axes([marg, marg, 1-1.8*marg, 1-1.8*marg], aspect=1)
29+
ax = fig.add_axes([0.2, 0.17, 0.68, 0.7], aspect=1)
3130

3231
ax.xaxis.set_major_locator(MultipleLocator(1.000))
3332
ax.xaxis.set_minor_locator(AutoMinorLocator(4))
@@ -68,34 +67,34 @@ def annotate(x, y, text, code, radius=0.15):
6867

6968
ax.text(x, y-0.2, text, zorder=100,
7069
ha='center', va='top', weight='bold', color=royal_blue,
71-
style='italic', fontfamily='monospace',
70+
style='italic', fontfamily='Courier New',
7271
path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))])
7372

7473
ax.text(x, y-0.33, code, zorder=100,
7574
ha='center', va='top', weight='normal', color='0.0',
76-
fontfamily='Courier New', fontsize='medium',
75+
fontfamily='monospace', fontsize='medium',
7776
path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))])
7877

7978

80-
annotate(3.25, -0.10, "Minor tick label", "ax.xaxis.set_minor_formatter")
81-
annotate(-0.03, 1.05, "Major tick", "ax.yaxis.set_major_locator")
82-
annotate(0.00, 3.75, "Minor tick", "ax.yaxis.set_minor_locator")
83-
annotate(-0.15, 3.00, "Major tick label", "ax.yaxis.set_major_formatter")
84-
annotate(1.90, -0.32, "xlabel", "ax.set_xlabel")
85-
annotate(-0.27, 1.68, "ylabel", "ax.set_ylabel")
86-
annotate(1.58, 4.13, "Title", "ax.set_title")
87-
annotate(1.75, 2.80, "Line", "ax.plot")
88-
annotate(2.25, 1.54, "Markers", "ax.scatter")
89-
annotate(3.00, 3.00, "Grid", "ax.grid")
90-
annotate(3.60, 3.65, "Legend", "ax.legend")
91-
annotate(2.5, 0.55, "Axes", "fig.subplots")
92-
annotate(4.185, 4.3, "Figure", "plt.figure")
79+
annotate(3.495, -0.10, "Minor tick label", "ax.xaxis.set_minor_formatter()")
80+
annotate(-0.03, 1.05, "Major tick", "ax.yaxis.set_major_locator()")
81+
annotate(0.00, 3.75, "Minor tick", "ax.yaxis.set_minor_locator()")
82+
annotate(-0.15, 3.00, "Major tick label", "ax.yaxis.set_major_formatter()")
83+
annotate(1.68, -0.37, "xlabel", "ax.set_xlabel()")
84+
annotate(-0.35, 1.68, "ylabel", "ax.set_ylabel()")
85+
annotate(1.52, 4.15, "Title", "ax.set_title()")
86+
annotate(1.75, 2.80, "Line", "ax.plot()")
87+
annotate(2.25, 1.54, "Markers", "ax.scatter()")
88+
annotate(3.00, 3.00, "Grid", "ax.grid()")
89+
annotate(3.60, 3.62, "Legend", "ax.legend()")
90+
annotate(2.5, 0.55, "Axes", "fig.subplots()")
91+
annotate(4, 4.5, "Figure", "plt.figure()")
9392
annotate(0.65, 0.01, "x Axis", "ax.xaxis")
9493
annotate(0, 0.44, "y Axis", "ax.yaxis")
9594
annotate(4.0, 0.7, "Spine", "ax.spines")
9695

9796
# frame around figure
98-
fig.patch.set(linewidth=10, edgecolor='0.5')
97+
fig.patch.set(linewidth=4, edgecolor='0.5')
9998
plt.show()
10099

101100

0 commit comments

Comments
 (0)