Skip to content

Commit 09b29d8

Browse files
committed
Simplify examples to use defaults more often
1 parent 4513182 commit 09b29d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+119
-105
lines changed

examples/api/demo_affine_image.py

100644100755
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def imshow_affine(ax, z, *kl, **kwargs):
3737

3838
fig, (ax1, ax2) = plt.subplots(1, 2)
3939
Z = get_image()
40-
im1 = imshow_affine(ax1, Z, interpolation='none', cmap=cm.jet,
40+
im1 = imshow_affine(ax1, Z, interpolation='none',
4141
origin='lower',
4242
extent=[-2, 4, -3, 2], clip_on=True)
4343

@@ -48,15 +48,15 @@ def imshow_affine(ax, z, *kl, **kwargs):
4848
x1, x2, y1, y2 = im1.get_extent()
4949
x3, y3 = x2, y1
5050

51-
ax1.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], "r--", lw=3,
51+
ax1.plot([x1, x2, x2, x1, x1], [y1, y1, y2, y2, y1], "--",
5252
transform=trans_data2)
5353

5454
ax1.set_xlim(-3, 5)
5555
ax1.set_ylim(-4, 4)
5656

5757
# image skew
5858

59-
im2 = ax2.imshow(Z, interpolation='none', cmap=cm.jet,
59+
im2 = ax2.imshow(Z, interpolation='none',
6060
origin='lower',
6161
extent=[-2, 4, -3, 2], clip_on=True)
6262
im2._image_skew_coordinate = (3, -2)

examples/api/filled_step.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ def filled_hist(ax, edges, values, bottoms=None, orientation='v',
6161
values = np.r_[values, values[-1]]
6262
bottoms = np.r_[bottoms, bottoms[-1]]
6363
if orientation == 'h':
64-
return ax.fill_betweenx(edges, values, bottoms, **kwargs)
64+
return ax.fill_betweenx(edges, values, bottoms, left_margin=False,
65+
**kwargs)
6566
elif orientation == 'v':
66-
return ax.fill_between(edges, values, bottoms, **kwargs)
67+
return ax.fill_between(edges, values, bottoms, bottom_margin=False,
68+
**kwargs)
6769
else:
6870
raise AssertionError("you should never be here")
6971

@@ -206,3 +208,5 @@ def stack_hist(ax, stacked_data, sty_cycle, bottoms=None,
206208
ax1.set_xlabel('counts')
207209
ax1.set_ylabel('x')
208210
ax2.set_ylabel('x')
211+
212+
plt.show()

examples/api/histogram_path_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
barpath = path.Path.make_compound_path_from_polys(XY)
3737

3838
# make a patch out of it
39-
patch = patches.PathPatch(
40-
barpath, facecolor='blue', edgecolor='gray', alpha=0.8)
39+
patch = patches.PathPatch(barpath, facecolor='blue')
4140
ax.add_patch(patch)
4241

4342
# update the view limits

examples/api/image_zcoord.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
X = 10*np.random.rand(5, 3)
1010

1111
fig, ax = plt.subplots()
12-
ax.imshow(X, cmap=cm.jet, interpolation='nearest')
12+
ax.imshow(X, interpolation='nearest')
1313

1414
numrows, numcols = X.shape
1515

examples/api/patch_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
patches.append(polygon)
4040

4141
colors = 100*np.random.rand(len(patches))
42-
p = PatchCollection(patches, cmap=matplotlib.cm.jet, alpha=0.4)
42+
p = PatchCollection(patches, alpha=0.4)
4343
p.set_array(np.array(colors))
4444
ax.add_collection(p)
4545
plt.colorbar(p)

examples/api/power_norm_demo.py

100644100755
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
for i, gamma in enumerate(gammas):
2121
plt.subplot(xgrid, ygrid, i + 2)
22-
plt.title('Power law normalization\n$(\gamma=%1.1f)$' % gamma)
22+
plt.title('Power law\n$(\gamma=%1.1f)$' % gamma)
2323
plt.hist2d(data[:, 0], data[:, 1],
2424
bins=100, norm=mcolors.PowerNorm(gamma))
2525

26-
plt.subplots_adjust(hspace=0.39)
26+
plt.subplots_adjust(hspace=0.8)
27+
plt.savefig("test.png")
2728
plt.show()

examples/api/sankey_demo_basics.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@
4242
orientations=[-1, 1, 0, 1, 1, 1, -1, -1, 0],
4343
pathlengths=[0.25, 0.25, 0.25, 0.25, 0.25, 0.6, 0.25, 0.25,
4444
0.25],
45-
patchlabel="Widget\nA",
46-
alpha=0.2, lw=2.0) # Arguments to matplotlib.patches.PathPatch()
45+
patchlabel="Widget\nA") # Arguments to matplotlib.patches.PathPatch()
4746
diagrams = sankey.finish()
48-
diagrams[0].patch.set_facecolor('#37c959')
4947
diagrams[0].texts[-1].set_color('r')
5048
diagrams[0].text.set_fontweight('bold')
5149
# Notice:
@@ -66,7 +64,7 @@
6664
sankey = Sankey(ax=ax, unit=None)
6765
sankey.add(flows=flows, label='one',
6866
orientations=[-1, 1, 0, 1, 1, 1, -1, -1, 0])
69-
sankey.add(flows=[-0.25, 0.15, 0.1], fc='#37c959', label='two',
67+
sankey.add(flows=[-0.25, 0.15, 0.1], label='two',
7068
orientations=[-1, -1, -1], prior=0, connect=(0, 0))
7169
diagrams = sankey.finish()
7270
diagrams[-1].patch.set_hatch('/')

examples/api/sankey_demo_links.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
def side(sankey, n=1):
1313
"""Generate a side chain."""
1414
prior = len(sankey.diagrams)
15-
colors = cycle(['orange', 'b', 'g', 'r', 'c', 'm', 'y'])
1615
for i in range(0, 2*n, 2):
1716
sankey.add(flows=[1, -1], orientations=[-1, -1],
18-
patchlabel=str(prior + i), facecolor=next(colors),
17+
patchlabel=str(prior + i),
1918
prior=prior + i - 1, connect=(1, 0), alpha=0.5)
2019
sankey.add(flows=[1, -1], orientations=[1, 1],
21-
patchlabel=str(prior + i + 1), facecolor=next(colors),
20+
patchlabel=str(prior + i + 1),
2221
prior=prior + i, connect=(1, 0), alpha=0.5)
2322

2423

examples/api/sankey_demo_old.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def put_labels(labels, positions, output=True):
187187

188188
patch, (intexts, outtexts) = sankey(ax, outputs=outputs,
189189
outlabels=outlabels, inputs=inputs,
190-
inlabels=None, fc='g', alpha=0.2)
190+
inlabels=None)
191191
outtexts[1].set_color('r')
192192
outtexts[-1].set_fontweight('bold')
193193

examples/api/skewt.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ def _set_lim_and_transforms(self):
238238

239239
# Plot the data using normal plotting functions, in this case using
240240
# log scaling in Y, as dicatated by the typical meteorological plot
241-
ax.semilogy(T, p, 'r')
242-
ax.semilogy(Td, p, 'g')
241+
ax.semilogy(T, p)
242+
ax.semilogy(Td, p)
243243

244244
# An example of a slanted line at constant X
245-
l = ax.axvline(0, color='b')
245+
l = ax.axvline(0)
246246

247247
# Disables the log-formatting that comes with semilogy
248248
ax.yaxis.set_major_formatter(ScalarFormatter())

examples/lines_bars_and_markers/barh_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
performance = 3 + 10 * np.random.rand(len(people))
1414
error = np.random.rand(len(people))
1515

16-
plt.barh(y_pos, performance, xerr=error, align='center', alpha=0.4)
16+
plt.barh(y_pos, performance, xerr=error, align='center')
1717
plt.yticks(y_pos, people)
1818
plt.xlabel('Performance')
1919
plt.title('How fast do you want to go today?')

examples/lines_bars_and_markers/fill_demo.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@
44
import numpy as np
55
import matplotlib.pyplot as plt
66

7-
8-
x = np.linspace(0, 1)
7+
x = np.linspace(0, 1, 500)
98
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
109

11-
plt.fill(x, y, 'r')
10+
plt.fill(x, y)
1211
plt.grid(True)
1312
plt.show()

examples/lines_bars_and_markers/fill_demo_features.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111
import matplotlib.pyplot as plt
1212

13-
x = np.linspace(0, 2 * np.pi, 100)
13+
x = np.linspace(0, 2 * np.pi, 500)
1414
y1 = np.sin(x)
1515
y2 = np.sin(3 * x)
1616
plt.fill(x, y1, 'b', x, y2, 'r', alpha=0.3)

examples/lines_bars_and_markers/line_demo_dash_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.pyplot as plt
99

1010

11-
x = np.linspace(0, 10)
11+
x = np.linspace(0, 10, 500)
1212
line, = plt.plot(x, np.sin(x), '--', linewidth=2)
1313

1414
dashes = [10, 5, 100, 5] # 10 points on, 5 off, 100 on, 5 off

examples/lines_bars_and_markers/line_styles_reference.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def nice_repr(text):
2525

2626
linestyles = ['-', '--', '-.', ':']
2727
for y, linestyle in enumerate(linestyles):
28-
ax.text(-0.5, y, nice_repr(linestyle), **text_style)
28+
ax.text(-0.1, y, nice_repr(linestyle), **text_style)
2929
ax.plot(y * points, linestyle=linestyle, color=color, linewidth=3)
3030
format_axes(ax)
3131
ax.set_title('line styles')

examples/mplot3d/lorenz_attractor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def lorenz(x, y, z, s=10, r=28, b=2.667):
4040
fig = plt.figure()
4141
ax = fig.gca(projection='3d')
4242

43-
ax.plot(xs, ys, zs)
43+
ax.plot(xs, ys, zs, lw=0.5)
4444
ax.set_xlabel("X Axis")
4545
ax.set_ylabel("Y Axis")
4646
ax.set_zlabel("Z Axis")

examples/mplot3d/surface3d_demo3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
colors[x, y] = colortuple[(x + y) % len(colortuple)]
2222

2323
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, facecolors=colors,
24-
linewidth=0, antialiased=False)
24+
linewidth=0)
2525

2626
ax.set_zlim3d(-1, 1)
2727
ax.w_zaxis.set_major_locator(LinearLocator(6))

examples/mplot3d/trisurf3d_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
fig = plt.figure()
2828
ax = fig.gca(projection='3d')
2929

30-
ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2)
30+
ax.plot_trisurf(x, y, z, cmap=cm.jet, linewidth=0.2, antialiased=True)
3131

3232
plt.show()

examples/pie_and_polar_charts/pie_demo_features.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@
2121
# The slices will be ordered and plotted counter-clockwise.
2222
labels = 'Frogs', 'Hogs', 'Dogs', 'Logs'
2323
sizes = [15, 30, 45, 10]
24-
colors = ['yellowgreen', 'gold', 'lightskyblue', 'lightcoral']
2524
explode = (0, 0.1, 0, 0) # only "explode" the 2nd slice (i.e. 'Hogs')
2625

27-
plt.pie(sizes, explode=explode, labels=labels, colors=colors,
26+
plt.pie(sizes, explode=explode, labels=labels,
2827
autopct='%1.1f%%', shadow=True, startangle=90)
2928
# Set aspect ratio to be equal so that pie is drawn as a circle.
3029
plt.axis('equal')
@@ -33,16 +32,16 @@
3332
ax = fig.gca()
3433
import numpy as np
3534

36-
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
35+
ax.pie(np.random.random(4), explode=explode, labels=labels,
3736
autopct='%1.1f%%', shadow=True, startangle=90,
3837
radius=0.25, center=(0, 0), frame=True)
39-
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
38+
ax.pie(np.random.random(4), explode=explode, labels=labels,
4039
autopct='%1.1f%%', shadow=True, startangle=90,
4140
radius=0.25, center=(1, 1), frame=True)
42-
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
41+
ax.pie(np.random.random(4), explode=explode, labels=labels,
4342
autopct='%1.1f%%', shadow=True, startangle=90,
4443
radius=0.25, center=(0, 1), frame=True)
45-
ax.pie(np.random.random(4), explode=explode, labels=labels, colors=colors,
44+
ax.pie(np.random.random(4), explode=explode, labels=labels,
4645
autopct='%1.1f%%', shadow=True, startangle=90,
4746
radius=0.25, center=(1, 0), frame=True)
4847

examples/pylab_examples/annotation_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
t = np.arange(0.0, 5.0, 0.01)
5050
s = np.cos(2*np.pi*t)
51-
line, = ax.plot(t, s, lw=3, color='purple')
51+
line, = ax.plot(t, s, lw=3)
5252

5353
ax.annotate('axes center', xy=(.5, .5), xycoords='axes fraction',
5454
horizontalalignment='center', verticalalignment='center')
@@ -97,7 +97,7 @@
9797
ax = fig.add_subplot(111, projection='polar')
9898
r = np.arange(0, 1, 0.001)
9999
theta = 2*2*np.pi*r
100-
line, = ax.plot(theta, r, color='#ee8d18', lw=3)
100+
line, = ax.plot(theta, r)
101101

102102
ind = 800
103103
thisr, thistheta = r[ind], theta[ind]

examples/pylab_examples/annotation_demo2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
t = np.arange(0.0, 5.0, 0.01)
1111
s = np.cos(2*np.pi*t)
12-
line, = ax.plot(t, s, lw=3, color='purple')
12+
line, = ax.plot(t, s, lw=3)
1313

1414
ax.annotate('arrowstyle', xy=(0, 1), xycoords='data',
1515
xytext=(-50, 30), textcoords='offset points',

examples/pylab_examples/bar_stacked.py

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
ind = np.arange(N) # the x locations for the groups
1313
width = 0.35 # the width of the bars: can also be len(x) sequence
1414

15-
p1 = plt.bar(ind, menMeans, width, color='r', yerr=menStd)
16-
p2 = plt.bar(ind, womenMeans, width, color='y',
15+
p1 = plt.bar(ind, menMeans, width, yerr=menStd)
16+
p2 = plt.bar(ind, womenMeans, width,
1717
bottom=menMeans, yerr=womenStd)
1818

1919
plt.ylabel('Scores')

examples/pylab_examples/figure_title.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ def f(t):
1414

1515

1616
plt.subplot(121)
17-
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k')
17+
plt.plot(t1, f(t1), 'o', t2, f(t2), '-')
1818
plt.title('subplot 1')
1919
plt.ylabel('Damped oscillation')
2020
plt.suptitle('This is a somewhat long figure title', fontsize=16)
2121

2222

2323
plt.subplot(122)
24-
plt.plot(t3, np.cos(2*np.pi*t3), 'r--')
24+
plt.plot(t3, np.cos(2*np.pi*t3), '--')
2525
plt.xlabel('time (s)')
2626
plt.title('subplot 2')
2727
plt.ylabel('Undamped')
2828

29+
plt.subplots_adjust(left=0.2, wspace=0.8, top=0.8)
30+
2931
plt.show()

examples/pylab_examples/fill_betweenx_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
ax3 = fig.add_subplot(313, sharex=ax1)
1717

1818
ax1.fill_betweenx(x, 0, y1)
19-
ax1.set_ylabel('between y1 and 0')
19+
ax1.set_ylabel('(y1, 0)')
2020

2121
ax2.fill_betweenx(x, y1, 1)
22-
ax2.set_ylabel('between y1 and 1')
22+
ax2.set_ylabel('(y1, 1)')
2323

2424
ax3.fill_betweenx(x, y1, y2)
25-
ax3.set_ylabel('between y1 and y2')
25+
ax3.set_ylabel('(y1, y2)')
2626
ax3.set_xlabel('x')
2727

2828
# now fill between y1 and y2 where a logical condition is met. Note

examples/pylab_examples/geo_demo.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
import matplotlib.pyplot as plt
22

3-
plt.subplot(221, projection="aitoff")
3+
plt.figure()
4+
plt.subplot(111, projection="aitoff")
45
plt.title("Aitoff")
56
plt.grid(True)
67

7-
plt.subplot(222, projection="hammer")
8+
plt.figure()
9+
plt.subplot(111, projection="hammer")
810
plt.title("Hammer")
911
plt.grid(True)
1012

11-
plt.subplot(223, projection="lambert")
13+
plt.figure()
14+
plt.subplot(111, projection="lambert")
1215
plt.title("Lambert")
1316
plt.grid(True)
1417

15-
plt.subplot(224, projection="mollweide")
18+
plt.figure()
19+
plt.subplot(111, projection="mollweide")
1620
plt.title("Mollweide")
1721
plt.grid(True)
1822

examples/pylab_examples/griddata_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
zi = griddata(x, y, z, xi, yi, interp='linear')
1717
# contour the gridded data, plotting dots at the nonuniform data points.
1818
CS = plt.contour(xi, yi, zi, 15, linewidths=0.5, colors='k')
19-
CS = plt.contourf(xi, yi, zi, 15, cmap=plt.cm.rainbow,
19+
CS = plt.contourf(xi, yi, zi, 15,
2020
vmax=abs(zi).max(), vmin=-abs(zi).max())
2121
plt.colorbar() # draw colorbar
2222
# plot data points.
23-
plt.scatter(x, y, marker='o', c='b', s=5, zorder=10)
23+
plt.scatter(x, y, marker='o', s=5, zorder=10)
2424
plt.xlim(-2, 2)
2525
plt.ylim(-2, 2)
2626
plt.title('griddata test (%d points)' % npts)

examples/pylab_examples/legend_demo2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
# extracts the first element of the list into l1 using tuple
1111
# unpacking. So l1 is a Line2D instance, not a sequence of lines
1212
l1, = plt.plot(t2, np.exp(-t2))
13-
l2, l3 = plt.plot(t2, np.sin(2 * np.pi * t2), '--go', t1, np.log(1 + t1), '.')
14-
l4, = plt.plot(t2, np.exp(-t2) * np.sin(2 * np.pi * t2), 'rs-.')
13+
l2, l3 = plt.plot(t2, np.sin(2 * np.pi * t2), '--o', t1, np.log(1 + t1), '.')
14+
l4, = plt.plot(t2, np.exp(-t2) * np.sin(2 * np.pi * t2), 's-.')
1515

1616
plt.legend((l2, l4), ('oscillatory', 'damped'), loc='upper right', shadow=True)
1717
plt.xlabel('time')

examples/pylab_examples/legend_demo4.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
bottom_ax.stem([0.3, 1.5, 2.7], [1, 3.6, 2.7], label="stem test")
1919
bottom_ax.legend()
2020

21+
plt.subplots_adjust(hspace=0.7)
2122
plt.show()

examples/pylab_examples/mathtext_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
fig = figure()
1010
fig.subplots_adjust(bottom=0.2)
1111

12-
ax = fig.add_subplot(111, facecolor='y')
12+
ax = fig.add_subplot(111)
1313
ax.plot([1, 2, 3], 'r')
1414
x = np.arange(0.0, 3.0, 0.1)
1515

0 commit comments

Comments
 (0)