Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2c29fd1

Browse files
authored
Merge pull request #2 from Kojoley/suggestion-pr7072
Suggestions for #7072
2 parents f2ef761 + d8f03c6 commit 2c29fd1

File tree

1 file changed

+45
-50
lines changed

1 file changed

+45
-50
lines changed

examples/showcase/anatomy.py

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import numpy as np
44
import matplotlib.pyplot as plt
5-
from matplotlib.patches import Circle
65
from matplotlib.ticker import MultipleLocator, FuncFormatter
76

87
np.random.seed(123)
@@ -12,58 +11,54 @@
1211
Y2 = 1+np.cos(1+X/0.75)/2
1312
Y3 = np.random.uniform(Y1, Y2, len(X))
1413

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

1817

1918
def minor_tick(x, pos):
2019
if not x % 1.0:
2120
return ""
2221
return "%.2f" % x
2322

24-
plt.axes().xaxis.set_major_locator(MultipleLocator(1.000))
25-
plt.axes().xaxis.set_minor_locator(MultipleLocator(0.250))
26-
plt.axes().yaxis.set_major_locator(MultipleLocator(1.000))
27-
plt.axes().yaxis.set_minor_locator(MultipleLocator(0.250))
28-
plt.axes().xaxis.set_minor_formatter(FuncFormatter(minor_tick))
23+
ax.xaxis.set_major_locator(MultipleLocator(1.000))
24+
ax.xaxis.set_minor_locator(MultipleLocator(0.250))
25+
ax.yaxis.set_major_locator(MultipleLocator(1.000))
26+
ax.yaxis.set_minor_locator(MultipleLocator(0.250))
27+
ax.xaxis.set_minor_formatter(FuncFormatter(minor_tick))
2928

30-
plt.xlim(0, 4)
31-
plt.ylim(0, 4)
29+
ax.set_xlim(0, 4)
30+
ax.set_ylim(0, 4)
3231

33-
plt.tick_params(which='major', width=1.0)
34-
plt.tick_params(which='major', length=10)
35-
plt.tick_params(which='minor', width=1.0, labelsize=10)
36-
plt.tick_params(which='minor', length=5, labelsize=10, labelcolor='0.25')
32+
ax.tick_params(which='major', width=1.0)
33+
ax.tick_params(which='major', length=10)
34+
ax.tick_params(which='minor', width=1.0, labelsize=10)
35+
ax.tick_params(which='minor', length=5, labelsize=10, labelcolor='0.25')
3736

38-
plt.grid(linestyle="--", linewidth=0.5, color='.25', zorder=-10)
37+
ax.grid(linestyle="--", linewidth=0.5, color='.25', zorder=-10)
3938

40-
plt.plot(X, Y1, c=(0.25, 0.25, 1.00), lw=2, label="Blue signal", zorder=10)
41-
plt.plot(X, Y2, c=(1.00, 0.25, 0.25), lw=2, label="Red signal")
42-
plt.scatter(X, Y3, c='w')
39+
ax.plot(X, Y1, c=(0.25, 0.25, 1.00), lw=2, label="Blue signal", zorder=10)
40+
ax.plot(X, Y2, c=(1.00, 0.25, 0.25), lw=2, label="Red signal")
41+
ax.scatter(X, Y3, c='w')
4342

44-
plt.title("Anatomy of a figure", fontsize=20)
45-
plt.xlabel("X axis label")
46-
plt.ylabel("Y axis label")
43+
ax.set_title("Anatomy of a figure", fontsize=20)
44+
ax.set_xlabel("X axis label")
45+
ax.set_ylabel("Y axis label")
4746

48-
plt.legend(frameon=False)
47+
ax.legend(frameon=False)
4948

5049

5150
def circle(x, y, radius=0.15):
52-
center = x, y
53-
circle = Circle(center, radius, clip_on=False, zorder=10,
54-
edgecolor='white', facecolor='none', linewidth=5.0)
55-
plt.axes().add_artist(circle)
56-
circle = Circle(center, radius, clip_on=False, zorder=20,
57-
edgecolor='none', facecolor='black', alpha=.025)
58-
plt.axes().add_artist(circle)
59-
circle = Circle(center, radius, clip_on=False, zorder=30,
60-
edgecolor='black', facecolor='none', linewidth=1.0)
61-
plt.axes().add_artist(circle)
51+
from matplotlib.patches import Circle
52+
from matplotlib.patheffects import withStroke
53+
circle = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=1,
54+
edgecolor='black', facecolor=(0, 0, 0, .0125),
55+
path_effects=[withStroke(linewidth=5, foreground='w')])
56+
ax.add_artist(circle)
6257

6358

6459
def text(x, y, text):
65-
plt.text(x, y, text, backgroundcolor="white",
66-
ha='center', va='top', weight='bold', color='blue')
60+
ax.text(x, y, text, backgroundcolor="white",
61+
ha='center', va='top', weight='bold', color='blue')
6762

6863

6964
# Minor tick
@@ -123,21 +118,21 @@ def text(x, y, text):
123118
text(-0.3, 0.45, "Figure")
124119

125120
color = 'blue'
126-
plt.annotate('Spines', xy=(4.0, 0.35), xycoords='data',
127-
xytext=(3.3, 0.5), textcoords='data',
128-
weight='bold', color=color,
129-
arrowprops=dict(arrowstyle='->',
130-
connectionstyle="arc3",
131-
color=color))
132-
133-
plt.annotate('', xy=(3.15, 0.0), xycoords='data',
134-
xytext=(3.45, 0.45), textcoords='data',
135-
weight='bold', color=color,
136-
arrowprops=dict(arrowstyle='->',
137-
connectionstyle="arc3",
138-
color=color))
139-
140-
plt.text(4.0, -0.4, "Made with http://matplotlib.org",
141-
fontsize=10, ha="right", color='.5')
121+
ax.annotate('Spines', xy=(4.0, 0.35), xycoords='data',
122+
xytext=(3.3, 0.5), textcoords='data',
123+
weight='bold', color=color,
124+
arrowprops=dict(arrowstyle='->',
125+
connectionstyle="arc3",
126+
color=color))
127+
128+
ax.annotate('', xy=(3.15, 0.0), xycoords='data',
129+
xytext=(3.45, 0.45), textcoords='data',
130+
weight='bold', color=color,
131+
arrowprops=dict(arrowstyle='->',
132+
connectionstyle="arc3",
133+
color=color))
134+
135+
ax.text(4.0, -0.4, "Made with http://matplotlib.org",
136+
fontsize=10, ha="right", color='.5')
142137

143138
plt.show()

0 commit comments

Comments
 (0)