8000 FIX: cleanup · matplotlib/matplotlib@5abb978 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5abb978

Browse files
committed
FIX: cleanup
1 parent 8ce4421 commit 5abb978

File tree

1 file changed

+22
-28
lines changed

1 file changed

+22
-28
lines changed

examples/showcase/anatomy.py

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,18 @@
66
This figure shows the name of several matplotlib elements composing a figure
77
"""
88

9-
import matplotlib.font_manager
10-
matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
119

1210
import numpy as np
1311
import matplotlib.pyplot as plt
12+
from matplotlib.patches import Circle
13+
from matplotlib.patheffects import withStroke
1414
from matplotlib.ticker import AutoMinorLocator, MultipleLocator
1515

1616
royal_blue = "#002082"
1717
royal_blue = [0, 20/256, 82/256]
1818

19+
# make the figure
20+
1921
np.random.seed(19680801)
2022

2123
X = np.linspace(0.5, 3.5, 100)
@@ -55,30 +57,30 @@ def minor_tick(x, pos):
5557
marker='o', markerfacecolor='none', markeredgecolor='C4', markeredgewidth=2)
5658

5759
ax.set_title("Anatomy of a figure", fontsize=20, verticalalignment='bottom')
58-
ax.set_xlabel("X axis label", fontsize=14)
59-
ax.set_ylabel("Y axis label", fontsize=14)
60+
ax.set_xlabel("x Axis label", fontsize=14)
61+
ax.set_ylabel("y Axis label", fontsize=14)
6062

6163
ax.legend(loc="upper right", fontsize=14)
6264

65+
# Annotate the figure
6366

6467
def circle(x, y, radius=0.15):
65-
from matplotlib.patches import Circle
66-
from matplotlib.patheffects import withStroke
67-
circle = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=2.5,
68-
edgecolor=royal_blue + [0.6], facecolor=(0, 0, 0, .0),
69-
path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))])
70-
ax.add_artist(circle)
68+
c = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=2.5,
69+
edgecolor=royal_blue + [0.6], facecolor='none',
70+
path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))])
71+
ax.add_artist(c)
7172

7273

7374
def text(x, y, text):
74-
ax.text(x, y, text, backgroundcolor=(1, 1, 1, 1), zorder=100,
75+
ax.text(x, y, text, zorder=100,
7576
ha='center', va='top', weight='bold', color=royal_blue,
76-
style='italic', fontfamily='monospace')
77+
style='italic', fontfamily='monospace',
78+
path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))])
7779

7880

7981
# Minor tick
80-
circle(0.50, -0.10)
81-
text(0.50, -0.32, "Minor tick label")
82+
circle(3.25, -0.10)
83+
text(3.25, -0.32, "Minor tick label")
8284

8385
# Major tick
8486
circle(-0.03, 4.00)
@@ -94,11 +96,11 @@ def text(x, y, text):
9496

9597
# X Label
9698
circle(1.90, -0.27)
97-
text(1.90, -0.47, "X axis label")
99+
text(1.90, -0.47, "xlabel")
98100

99101
# Y Label
100102
circle(-0.27, 1.75)
101-
text(-0.27, 1.55, "Y axis label")
103+
text(-0.27, 1.55, "ylabel")
102104

103105
# Title
104106
circle(1.58, 4.13)
@@ -108,10 +110,6 @@ def text(x, y, text):
108110
circle(1.75, 2.80)
109111
text(1.75, 2.60, "Line\n(line plot)")
110112

111-
# Red plot
112-
#circle(1.20, 0.60)
113-
#text(1.20, 0.40, "Line\n(line plot)")
114-
115113
# Scatter plot
116114
circle(2.25, 1.54)
117115
text(2.25, 1.34, "Markers\n(scatter plot)")
@@ -133,21 +131,17 @@ def text(x, y, text):
133131
text(3.5, 4.2, "Figure")
134132

135133
# Axis
136-
circle(2.7, 0.01)
137-
text(2.7, -0.2, "x Axis")
134+
circle(0.65, 0.01)
135+
text(0.65, -0.2, "x Axis")
138136

139137
# Axis
140-
circle(0, 1.0)
141-
text(0, 1.0-0.2, "y Axis")
138+
circle(0, 0.7)
139+
text(0, 0.7-0.2, "y Axis")
142140

143141
# Spine
144142
circle(4.0, 0.7)
145143
text(4.0, 0.7-0.2, "Spine")
146144

147-
148-
#ax.text(4.0, -0.4, "Made with https://matplotlib.org",
149-
# fontsize=10, ha="right", color='.5')
150-
151145
plt.show()
152146

153147

0 commit comments

Comments
 (0)
0