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

Skip to content

Commit 09b29d8

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

47 files changed

Lines changed: 119 additions & 105 deletions

Some content is hidden

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

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())

0 commit comments

Comments
 (0)