Skip to content

Commit 9cad25c

Browse files
committed
Update anatomy figure for 2.x style changes.
* Enable black edges on scatter markers. Also, use `plot` instead of `scatter` for @efiring. * Move major and minor tick annotation to left side, where they're visible. * Shift tick label and axis label annotations outward to match corrected handling of tick length. * Don't disable legend frame, which is not very distracting any more. * Don't set figure facecolor, which is already white by default now. * Use AutoMinorLocator to avoid minor ticks overlaying major ticks, causing a small glitch due to antialiasing. Fixes matplotlib#7113.
1 parent 5ee1eee commit 9cad25c

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

doc/faq/anatomy.png

-2.3 KB
Loading

examples/showcase/anatomy.py

+26-24
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
import numpy as np
44
import matplotlib.pyplot as plt
5-
from matplotlib.ticker import MultipleLocator, FuncFormatter
5+
from matplotlib.ticker import AutoMinorLocator, MultipleLocator, FuncFormatter
66

7-
np.random.seed(123)
7+
8+
np.random.seed(19680801)
89

910
X = np.linspace(0.5, 3.5, 100)
1011
Y1 = 3+np.cos(X)
1112
Y2 = 1+np.cos(1+X/0.75)/2
1213
Y3 = np.random.uniform(Y1, Y2, len(X))
1314

14-
fig = plt.figure(figsize=(8, 8), facecolor="w")
15+
fig = plt.figure(figsize=(8, 8))
1516
ax = fig.add_subplot(1, 1, 1, aspect=1)
1617

1718

@@ -21,9 +22,9 @@ def minor_tick(x, pos):
2122
return "%.2f" % x
2223

2324
ax.xaxis.set_major_locator(MultipleLocator(1.000))
24-
ax.xaxis.set_minor_locator(MultipleLocator(0.250))
25+
ax.xaxis.set_minor_locator(AutoMinorLocator(4))
2526
ax.yaxis.set_major_locator(MultipleLocator(1.000))
26-
ax.yaxis.set_minor_locator(MultipleLocator(0.250))
27+
ax.yaxis.set_minor_locator(AutoMinorLocator(4))
2728
ax.xaxis.set_minor_formatter(FuncFormatter(minor_tick))
2829

2930
ax.set_xlim(0, 4)
@@ -38,13 +39,14 @@ def minor_tick(x, pos):
3839

3940
ax.plot(X, Y1, c=(0.25, 0.25, 1.00), lw=2, label="Blue signal", zorder=10)
4041
ax.plot(X, Y2, c=(1.00, 0.25, 0.25), lw=2, label="Red signal")
41-
ax.scatter(X, Y3, c='w')
42+
ax.plot(X, Y3, linewidth=0,
43+
marker='o', markerfacecolor='w', markeredgecolor='k')
4244

43-
ax.set_title("Anatomy of a figure", fontsize=20)
45+
ax.set_title("Anatomy of a figure", fontsize=20, verticalalignment='bottom')
4446
ax.set_xlabel("X axis label")
4547
ax.set_ylabel("Y axis label")
4648

47-
ax.legend(frameon=False)
49+
ax.legend()
4850

4951

5052
def circle(x, y, radius=0.15):
@@ -62,32 +64,32 @@ def text(x, y, text):
6264

6365

6466
# Minor tick
65-
circle(0.50, -.05)
66-
text(0.50, -0.25, "Minor tick label")
67+
circle(0.50, -0.10)
68+
text(0.50, -0.32, "Minor tick label")
6769

6870
# Major tick
69-
circle(4.00, 2.00)
70-
text(4.00, 1.80, "Major tick")
71+
circle(-0.03, 4.00)
72+
text(0.03, 3.80, "Major tick")
7173

7274
# Minor tick
73-
circle(0.25, 4.00)
74-
text(0.25, 3.80, "Minor tick")
75+
circle(0.00, 3.50)
76+
text(0.00, 3.30, "Minor tick")
7577

7678
# Major tick label
77-
circle(-0.05, 3.00)
78-
text(-0.05, 2.80, "Major tick label")
79+
circle(-0.15, 3.00)
80+
text(-0.15, 2.80, "Major tick label")
7981

8082
# X Label
81-
circle(1.80, -0.22)
82-
text(1.80, -0.4, "X axis label")
83+
circle(1.80, -0.27)
84+
text(1.80, -0.45, "X axis label")
8385

8486
# Y Label
85-
circle(-0.20, 1.80)
86-
text(-0.20, 1.6, "Y axis label")
87+
circle(-0.27, 1.80)
88+
text(-0.27, 1.6, "Y axis label")
8789

8890
# Title
89-
circle(1.60, 4.10)
90-
text(1.60, 3.9, "Title")
91+
circle(1.60, 4.13)
92+
text(1.60, 3.93, "Title")
9193

9294
# Blue plot
9395
circle(1.75, 2.80)
@@ -106,8 +108,8 @@ def text(x, y, text):
106108
text(3.00, 2.80, "Grid")
107109

108110
# Legend
109-
circle(3.70, 3.75)
110-
text(3.70, 3.55, "Legend")
111+
circle(3.70, 3.80)
112+
text(3.70, 3.60, "Legend")
111113

112114
# Axes
113115
circle(0.5, 0.5)

0 commit comments

Comments
 (0)