Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c3ce41f

Browse filesBrowse files
committed
Avoid pyplot in showcase examples.
Also, fix a few minor warnings due to internal changes.
1 parent 99d8900 commit c3ce41f
Copy full SHA for c3ce41f

File tree

Expand file treeCollapse file tree

4 files changed

+33
-32
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+33
-32
lines changed

‎examples/showcase/bachelors_degrees_by_gender.py

Copy file name to clipboardExpand all lines: examples/showcase/bachelors_degrees_by_gender.py
+15-14Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,23 @@
4747
ax.set_xlim(1969.5, 2011.1)
4848
ax.set_ylim(-0.25, 90)
4949

50-
# Make sure your axis ticks are large enough to be easily read.
51-
# You don't want your viewers squinting to read your plot.
52-
plt.xticks(range(1970, 2011, 10), fontsize=14)
53-
plt.yticks(range(0, 91, 10), fontsize=14)
50+
# Set a fixed location and format for ticks.
51+
ax.set_xticks(range(1970, 2011, 10))
52+
ax.set_yticks(range(0, 91, 10))
5453
ax.xaxis.set_major_formatter(plt.FuncFormatter('{:.0f}'.format))
5554
ax.yaxis.set_major_formatter(plt.FuncFormatter('{:.0f}%'.format))
5655

5756
# Provide tick lines across the plot to help your viewers trace along
5857
# the axis ticks. Make sure that the lines are light and small so they
5958
# don't obscure the primary data lines.
60-
plt.grid(True, 'major', 'y', ls='--', lw=.5, c='k', alpha=.3)
59+
ax.grid(True, 'major', 'y', ls='--', lw=.5, c='k', alpha=.3)
6160

6261
# Remove the tick marks; they are unnecessary with the tick lines we just
63-
# plotted.
64-
plt.tick_params(axis='both', which='both', bottom=False, top=False,
65-
labelbottom=True, left=False, right=False, labelleft=True)
62+
# plotted. Make sure your axis ticks are large enough to be easily read.
63+
# You don't want your viewers squinting to read your plot.
64+
ax.tick_params(axis='both', which='both', labelsize=14,
65+
bottom=False, top=False, labelbottom=True,
66+
left=False, right=False, labelleft=True)
6667

6768
# Now that the plot is prepared, it's time to actually plot the data!
6869
# Note that I plotted the majors in order of the highest % in the final year.
@@ -84,10 +85,10 @@
8485
# Plot each line separately with its own color.
8586
column_rec_name = column.replace('\n', '_').replace(' ', '_')
8687

87-
line = plt.plot(gender_degree_data['Year'],
88-
gender_degree_data[column_rec_name],
89-
lw=2.5,
90-
color=color_sequence[rank])
88+
line = ax.plot(gender_degree_data['Year'],
89+
gender_degree_data[column_rec_name],
90+
lw=2.5,
91+
color=color_sequence[rank])
9192

9293
# Add a text label to the right end of every line. Most of the code below
9394
# is adding specific offsets y position because some labels overlapped.
@@ -98,7 +99,7 @@
9899

99100
# Again, make sure that all labels are large enough to be easily read
100101
# by the viewer.
101-
plt.text(2011.5, y_pos, column, fontsize=14, color=color_sequence[rank])
102+
ax.text(2011.5, y_pos, column, fontsize=14, color=color_sequence[rank])
102103

103104
# Make the title big enough so it spans the entire plot, but don't make it
104105
# so big that it requires two lines to show.
@@ -111,5 +112,5 @@
111112
# Finally, save the figure as a PNG.
112113
# You can also save it as a PDF, JPEG, etc.
113114
# Just change the file extension in this call.
114-
# plt.savefig('percent-bachelors-degrees-women-usa.png', bbox_inches='tight')
115+
# fig.savefig('percent-bachelors-degrees-women-usa.png', bbox_inches='tight')
115116
plt.show()

‎examples/showcase/integral.py

Copy file name to clipboardExpand all lines: examples/showcase/integral.py
+6-6Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def func(x):
2626
y = func(x)
2727

2828
fig, ax = plt.subplots()
29-
plt.plot(x, y, 'r', linewidth=2)
30-
plt.ylim(ymin=0)
29+
ax.plot(x, y, 'r', linewidth=2)
30+
ax.set_ylim(bottom=0)
3131

3232
# Make the shaded region
3333
ix = np.linspace(a, b)
@@ -36,11 +36,11 @@ def func(x):
3636
poly = Polygon(verts, facecolor='0.9', edgecolor='0.5')
3737
ax.add_patch(poly)
3838

39-
plt.text(0.5 * (a + b), 30, r"$\int_a^b f(x)\mathrm{d}x$",
40-
horizontalalignment='center', fontsize=20)
39+
ax.text(0.5 * (a + b), 30, r"$\int_a^b f(x)\mathrm{d}x$",
40+
horizontalalignment='center', fontsize=20)
4141

42-
plt.figtext(0.9, 0.05, '$x$')
43-
plt.figtext(0.1, 0.9, '$y$')
42+
fig.text(0.9, 0.05, '$x$')
43+
fig.text(0.1, 0.9, '$y$')
4444

4545
ax.spines['right'].set_visible(False)
4646
ax.spines['top'].set_visible(False)

‎examples/showcase/mandelbrot.py

Copy file name to clipboardExpand all lines: examples/showcase/mandelbrot.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def mandelbrot_set(xmin, xmax, ymin, ymax, xn, yn, maxiter, horizon=2.0):
6161
light = colors.LightSource(azdeg=315, altdeg=10)
6262
M = light.shade(M, cmap=plt.cm.hot, vert_exag=1.5,
6363
norm=colors.PowerNorm(0.3), blend_mode='hsv')
64-
plt.imshow(M, extent=[xmin, xmax, ymin, ymax], interpolation="bicubic")
64+
ax.imshow(M, extent=[xmin, xmax, ymin, ymax], interpolation="bicubic")
6565
ax.set_xticks([])
6666
ax.set_yticks([])
6767

‎examples/showcase/xkcd.py

Copy file name to clipboardExpand all lines: examples/showcase/xkcd.py
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@
1212

1313
with plt.xkcd():
1414
# Based on "Stove Ownership" from XKCD by Randall Munroe
15-
# http://xkcd.com/418/
15+
# https://xkcd.com/418/
1616

1717
fig = plt.figure()
1818
ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
1919
ax.spines['right'].set_color('none')
2020
ax.spines['top'].set_color('none')
21-
plt.xticks([])
22-
plt.yticks([])
21+
ax.set_xticks([])
22+
ax.set_yticks([])
2323
ax.set_ylim([-30, 10])
2424

2525
data = np.ones(100)
2626
data[70:] -= np.arange(30)
2727

28-
plt.annotate(
28+
ax.annotate(
2929
'THE DAY I REALIZED\nI COULD COOK BACON\nWHENEVER I WANTED',
3030
xy=(70, 1), arrowprops=dict(arrowstyle='->'), xytext=(15, -10))
3131

32-
plt.plot(data)
32+
ax.plot(data)
3333

34-
plt.xlabel('time')
35-
plt.ylabel('my overall health')
34+
ax.set_xlabel('time')
35+
ax.set_ylabel('my overall health')
3636
fig.text(
3737
0.5, 0.05,
3838
'"Stove Ownership" from xkcd by Randall Munroe',
@@ -42,7 +42,7 @@
4242

4343
with plt.xkcd():
4444
# Based on "The Data So Far" from XKCD by Randall Munroe
45-
# http://xkcd.com/373/
45+
# https://xkcd.com/373/
4646

4747
fig = plt.figure()
4848
ax = fig.add_axes((0.1, 0.2, 0.8, 0.7))
@@ -51,12 +51,12 @@
5151
ax.spines['top'].set_color('none')
5252
ax.xaxis.set_ticks_position('bottom')
5353
ax.set_xticks([0, 1])
54+
ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT'])
5455
ax.set_xlim([-0.5, 1.5])
56+
ax.set_yticks([])
5557
ax.set_ylim([0, 110])
56-
ax.set_xticklabels(['CONFIRMED BY\nEXPERIMENT', 'REFUTED BY\nEXPERIMENT'])
57-
plt.yticks([])
5858

59-
plt.title("CLAIMS OF SUPERNATURAL POWERS")
59+
ax.set_title("CLAIMS OF SUPERNATURAL POWERS")
6060

6161
fig.text(
6262
0.5, 0.05,

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.