8000 ENH: add code snippets · matplotlib/matplotlib@c5c8996 · GitHub
[go: up one dir, main page]

Skip to content

Commit c5c8996

Browse files
committed
ENH: add code snippets
1 parent 116d106 commit c5c8996

File tree

1 file changed

+36
-37
lines changed

1 file changed

+36
-37
lines changed

examples/showcase/anatomy.py

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

2828
fig = plt.figure(figsize=(8, 8), facecolor='1')
29-
marg = 0.13
29+
marg = 0.15
3030
ax = fig.add_axes([marg, marg, 1-1.8*marg, 1-1.8*marg], aspect=1,
3131
facecolor='1')
3232

@@ -68,7 +68,7 @@ def minor_tick(x, pos):
6868
# Annotate the figure
6969

7070

71-
def circle(x, y, radius=0.15):
71+
def just_circle(x, y, radius=0.15):
7272
c = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=2.5,
7373
edgecolor=royal_blue + [0.6], facecolor='none',
7474
path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))])
@@ -82,70 +82,69 @@ def text(x, y, text):
8282
path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))])
8383

8484

85-
# Minor tick
86-
circle(3.25, -0.10)
87-
text(3.25, -0.32, "Minor tick label")
85+
def code(x, y, text):
86+
ax.text(x, y, text, zorder=100,
87+
ha='center', va='top', weight='normal', color='0.0',
88+
fontfamily='Courier New', fontsize='medium',
89+
path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))])
90+
91+
92+
def circle(x, y, txt, cde, radius=0.15):
93+
just_circle(x, y, radius=radius)
94+
text(x, y-0.2, txt)
95+
code(x, y-0.33, cde)
96+
97+
# Minor tick label
98+
circle(3.25, -0.10, "Minor tick label",
99+
"ax.xaxis.set_minor_formatter")
88100

89101
# Major tick
90-
circle(-0.03, 4.00)
91-
text(0.03, 3.80, "Major tick")
102+
circle(-0.03, 1.05, "Major tick", "ax.yaxis.set_major_locator")
92103

93104
# Minor tick
94-
circle(0.00, 3.50)
95-
text(0.00, 3.30, "Minor tick")
105+
y = 3.75
106+
circle(0.00, 3.75, "Minor tick", "ax.yaxis.set_minor_locator")
96107

97108
# Major tick label
98-
circle(-0.15, 3.00)
99-
text(-0.15, 2.80, "Major tick label")
109+
circle(-0.15, 3.00, "Major tick label", "ax.yaxis.set_major_formatter")
100110

101111
# X Label
102-
circle(1.90, -0.27)
103-
text(1.90, -0.47, "xlabel")
112+
circle(1.90, -0.32, "xlabel", "ax.set_xlabel")
104113

105114
# Y Label
106-
circle(-0.27, 1.75)
107-
text(-0.27, 1.55, "ylabel")
115+
circle(-0.27, 1.68, "ylabel", "ax.set_ylabel")
108116

109117
# Title
110-
circle(1.58, 4.13)
111-
text(1.58, 3.93, "Title")
118+
circle(1.58, 4.13, "Title", "ax.set_title")
112119

113120
# Blue plot
114-
circle(1.75, 2.80)
115-
text(1.75, 2.60, "Line\n(line plot)")
121+
circle(1.75, 2.80, "Line", "ax.plot")
116122

117123
# Scatter plot
118-
circle(2.25, 1.54)
119-
text(2.25, 1.34, "Markers\n(scatter plot)")
124+
circle(2.25, 1.54, "Markers", "ax.scatter")
120125

121126
# Grid
122-
circle(3.00, 3.00)
123-
text(3.00, 2.80, "Grid")
127+
circle(3.00, 3.00, "Grid", "ax.grid")
124128

125129
# Legend
126-
circle(3.60, 3.65)
127-
text(3.60, 3.45, "Legend")
130+
circle(3.60, 3.65, "Legend", "ax.legend")
128131

129132
# Axes
130-
circle(0.5, 0.5)
131-
text(0.5, 0.3, "Axes")
133+
circle(2.5, 0.55, "Axes", "fig.subplots")
132134

133135
# Figure
134-
circle(4.185, 4.3)
135-
text(4.185, 4.1, "Figure")
136+
circle(4.185, 4.3, "Figure", "plt.figure")
136137

137-
# Axis
138-
circle(0.65, 0.01)
139-
text(0.65, -0.2, "x Axis")
138+
# x Axis
139+
circle(0.65, 0.01, "x Axis", "ax.xaxis")
140140

141-
# Axis
142-
circle(0, 0.7)
143-
text(0, 0.7-0.2, "y Axis")
141+
# y Axis
142+
circle(0, 0.44, "y Axis", "ax.yaxis")
144143

145144
# Spine
146-
circle(4.0, 0.7)
147-
text(4.0, 0.7-0.2, "Spine")
145+
circle(4.0, 0.7, "Spine", "ax.spines")
148146

147+
# frame around figure...
149148
fig.add_artist(Rectangle((0, 0), width=1, height=1, facecolor='none',
150149
edgecolor='0.5', linewidth=10))
151150

0 commit comments

Comments
 (0)
0