8000 _rebase - minor fixes · matplotlib/matplotlib@7de0cb1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7de0cb1

Browse files
committed
_rebase - minor fixes
1 parent 8d175b6 commit 7de0cb1

File tree

8 files changed

+30
-38
lines changed

8 files changed

+30
-38
lines changed

examples/images_contours_and_fields/contour_demo.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
fig, ax = plt.subplots()
3434
CS = ax.contour(X, Y, Z)
3535
ax.clabel(CS, inline=1, fontsize=10)
36-
ax.set_itle('Simplest default with labels')
36+
ax.set_title('Simplest default with labels')
3737

3838

3939
###############################################################################
@@ -90,27 +90,24 @@
9090
im = ax.imshow(Z, interpolation='bilinear', origin='lower',
9191
cmap=cm.gray, extent=(-3, 3, -2, 2))
9292
levels = np.arange(-1.2, 1.6, 0.2)
93-
CS = ax.contour(Z, levels,
94-
origin='lower',
95-
linewidths=2,
96-
extent=(-3, 3, -2, 2))
93+
CS = ax.contour(Z, levels, origin='lower', cmap='flag',
94+
linewidths=2, extent=(-3, 3, -2, 2))
9795

9896
# Thicken the zero contour.
9997
zc = CS.collections[6]
10098
plt.setp(zc, linewidth=4)
10199

102100
ax.clabel(CS, levels[1::2], # label every second level
103-
inline=1,
104-
fmt='%1.1f',
105-
fontsize=14)
101+
inline=1, fmt='%1.1f',
102+
cmap='flag', fontsize=14)
106103

107104
# make a colorbar for the contour lines
108105
CB = fig.colorbar(CS, shrink=0.8, extend='both')
109106

110107
ax.set_title('Lines with colorbar')
111108

112109
# We can still add a colorbar for the image, too.
113-
CBI = fig.colorbar(im, orientation='horizontal', shrink=0.8, cmap='flag')
110+
CBI = fig.colorbar(im, orientation='horizontal', shrink=0.8)
114111

115112
# This makes the original colorbar look a bit out of place,
116113
# so let's improve its position.

examples/images_contours_and_fields/contour_label_demo.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,6 @@
3232
# Make contour labels using creative float classes
3333
# Follows suggestion of Manuel Metz
3434

35-
plt.figure()
36-
37-
# Basic contour plot
38-
CS = plt.contour(X, Y, Z)
39-
40-
4135
# Define a class that forces representation of float to look a certain way
4236
# This remove trailing zero so '1.0' becomes '1'
4337
class nf(float):
@@ -49,6 +43,10 @@ def __repr__(self):
4943
return '%.1f' % self.__float__()
5044

5145

46+
# Basic contour plot
47+
fig, ax = plt.subplots()
48+
CS = ax.contour(X, Y, Z)
49+
5250
# Recast levels to new class
5351
CS.levels = [nf(val) for val in CS.levels]
5452

@@ -57,7 +55,8 @@ def __repr__(self):
5755
fmt = r'%r \%%'
5856
else:
5957
fmt = '%r %%'
60-
plt.clabel(CS, CS.levels, inline=True, fmt=fmt, fontsize=10)
58+
59+
ax.clabel(CS, CS.levels, inline=True, fmt=fmt, fontsize=10)
6160

6261
###############################################################################
6362
# Label contours with arbitrary strings using a dictionary

examples/images_contours_and_fields/contourf_hatching.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
fig1, ax1 = plt.subplots()
2424
cs = ax1.contourf(x, y, z, hatches=['-', '/', '\\', '//'],
2525
cmap='gray', extend='both', alpha=0.5)
26-
fig1.colorbar()
26+
fig1.colorbar(cs)
2727

2828
###############################################################################
2929
# Plot 2: a plot of hatches without color with a legend
@@ -38,6 +38,4 @@
3838
# create a legend for the contour set
3939
artists, labels = cs.legend_elements()
4040
ax2.legend(artists, labels, handleheight=2)
41-
42-
4341
plt.show()

examples/images_contours_and_fields/demo_bboximage.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
if __name__ == "__main__":
1313

14-
fig, ax = plt.subplots()
14+
fig, (ax1, ax2) = plt.subplots(ncols=2)
1515

16-
txt = ax.text(0.5, 0.5, "test", size=30, ha="center", color="w")
16+
txt = ax1.text(0.5, 0.5, "test", size=30, ha="center", color="w")
1717
kwargs = dict()
1818

1919
bbox_image = BboxImage(txt.get_window_extent,
@@ -24,9 +24,8 @@
2424
)
2525
a = np.arange(256).reshape(1, 256)/256.
2626
bbox_image.set_data(a)
27-
ax.add_artist(bbox_image)
27+
ax1.add_artist(bbox_image)
2828

29-
ax = plt.subplot(122)
3029
a = np.linspace(0, 1, 256).reshape(1, -1)
3130
a = np.vstack((a, a))
3231

@@ -50,7 +49,7 @@
5049
bbox0 = Bbox.from_bounds(ix*dx*(1 + xpad_fraction),
5150
1. - iy*dy*(1 + ypad_fraction) - dy,
5251
dx, dy)
53-
bbox = TransformedBbox(bbox0, ax.transAxes)
52+
bbox = TransformedBbox(bbox0, ax2.transAxes)
5453

5554
bbox_image = BboxImage(bbox,
5655
cmap=plt.get_cmap(m),
@@ -60,7 +59,7 @@
6059
)
6160

6261
bbox_image.set_data(a)
63-
ax.add_artist(bbox_image)
62+
ax2.add_artist(bbox_image)
6463

6564
plt.draw()
6665
plt.show()

examples/images_contours_and_fields/interpolation_methods.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434

3535
for ax, interp_method in zip(axes.flat, methods):
3636
ax.imshow(grid, interpolation=interp_method, cmap='viridis')
37-
ax.set_title(interp_method)
37+
ax.set_title(str(interp_method))
3838

3939
plt.show()

examples/images_contours_and_fields/quadmesh_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
# The color array can include masked values.
2727
Zm = np.ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z)
2828

29-
fig, axs = plt.subplots(1, 3)
29+
fig, axs = plt.subplots(nrows=1, ncols=3)
3030
axs[0].pcolormesh(Qx, Qz, Z, shading='gouraud')
3131
axs[0].set_title('Without masked values')
3232

@@ -42,5 +42,4 @@
4242
axs[2].set_title('With masked values')
4343

4444
fig.tight_layout()
45-
4645
plt.show()

examples/images_contours_and_fields/tricontour_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040

4141
fig1, ax1 = plt.subplots()
4242
ax1.set_aspect('equal')
43-
ax1.tricontourf(triang, z)
44-
fig1.colorbar()
43+
tcf = ax1.tricontourf(triang, z)
44+
fig1.colorbar(tcf)
4545
ax1.tricontour(triang, z, colors='k')
4646
ax1.set_title('Contour plot of Delaunay triangulation')
4747

@@ -103,8 +103,8 @@
103103

104104
fig2, ax2 = plt.subplots()
105105
ax2.set_aspect('equal')
106-
ax2.tricontourf(x, y, triangles, z)
107-
fig2.colorbar()
106+
tcf = ax2.tricontourf(x, y, triangles, z)
107+
fig2.colorbar(tcf)
108108
ax2.set_title('Contour plot of user-specified triangulation')
109109
ax2.set_xlabel('Longitude (degrees)')
110110
ax2.set_ylabel('Latitude (degrees)')

examples/images_contours_and_fields/tripcolor_demo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@
4040

4141
fig1, ax1 = plt.subplots()
4242
ax1.set_aspect('equal')
43-
ax1.tripcolor(triang, z, shading='flat')
44-
fig1.colorbar()
43+
tpc = ax1.tripcolor(triang, z, shading='flat')
44+
fig1.colorbar(tpc)
4545
ax1.set_title('tripcolor of Delaunay triangulation, flat shading')
4646

4747
###############################################################################
4848
# Illustrate Gouraud shading.
4949

5050
fig2, ax2 = plt.subplots()
5151
ax2.set_aspect('equal')
52-
ax2.tripcolor(triang, z, shading='gouraud')
53-
fig2.colorbar()
52+
tpc = ax2.tripcolor(triang, z, shading='gouraud')
53+
fig2.colorbar(tpc)
5454
ax2.set_title('tripcolor of Delaunay triangulation, gouraud shading')
5555

5656

@@ -117,8 +117,8 @@
117117

118118
fig3, ax3 = plt.subplots()
119119
ax3.set_aspect('equal')
120-
ax3.tripcolor(x, y, triangles, facecolors=zfaces, edgecolors='k')
121-
fig3.colorbar()
120+
tpc = ax3.tripcolor(x, y, triangles, facecolors=zfaces, edgecolors='k')
121+
fig3.colorbar(tpc)
122122
ax3.set_title('tripcolor of user-specified triangulation')
123123
ax3.set_xlabel('Longitude (degrees)')
124124
ax3.set_ylabel('Latitude (degrees)')

0 commit comments

Comments
 (0)
0