8000 DOC: switch to OO interface in color + image/contour examples · matplotlib/matplotlib@ff2f779 · GitHub
[go: up one dir, main page]

Skip to content

Commit ff2f779

Browse files
committed
DOC: switch to OO interface in color + image/contour examples
1 parent 3a41957 commit ff2f779

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

examples/color/color_cycle_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
ax1.set_title('Set axes color cycle to cmyk')
3232

3333
# Tweak spacing between subplots to prevent labels from overlapping
34-
plt.subplots_adjust(hspace=0.3)
34+
fig.subplots_adjust(hspace=0.3)
3535
plt.show()

examples/images_contours_and_fields/contourf_log.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
# Automatic selection of levels works; setting the
3232
# log locator tells contourf to use a log scale:
33-
cs = plt.contourf(X, Y, z, locator=ticker.LogLocator(), cmap=cm.PuBu_r)
33+
fig, ax = plt.subplots()
34+
cs = ax.contourf(X, Y, z, locator=ticker.LogLocator(), cmap=cm.PuBu_r)
3435

3536
# Alternatively, you can manually set the levels
3637
# and the norm:
@@ -41,6 +42,6 @@
4142

4243
# The 'extend' kwarg does not work yet with a log scale.
4344

44-
cbar = plt.colorbar()
45+
cbar = fig.colorbar()
4546

4647
plt.show()

examples/images_contours_and_fields/image_demo.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
image_file = cbook.get_sample_data('ada.png')
88
image = plt.imread(image_file)
99

10-
plt.imshow(image)
11-
plt.axis('off') # clear x- and y-axes
10+
fig, ax = plt.subplots()
11+
ax.imshow(image)
12+
ax.axis('off') # clear x- and y-axes
1213
plt.show()

examples/images_contours_and_fields/image_demo_clip_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
patch = patches.Circle((260, 200), radius=200, transform=ax.transData)
1515
im.set_clip_path(patch)
1616

17-
plt.axis('off')
17+
ax.axis('off')
1818
plt.show()

examples/images_contours_and_fields/interpolation_none_vs_nearest.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,13 @@
2323
[0.6, 0.3, 0.0, 0.2], [0.7, 0.9, 0.4, 0.6]])
2424

2525
# Create a 2x2 table of plots
26-
fig = plt.figure(figsize=[8.0, 7.5])
27-
ax = plt.subplot(2, 2, 1)
28-
ax.imshow(big_im, interpolation='none')
29-
ax = plt.subplot(2, 2, 2)
30-
ax.imshow(big_im, interpolation='nearest')
31-
ax = plt.subplot(2, 2, 3)
32-
ax.imshow(small_im, interpolation='none')
33-
ax = plt.subplot(2, 2, 4)
34-
ax.imshow(small_im, interpolation='nearest')
35-
plt.subplots_adjust(left=0.24, wspace=0.2, hspace=0.1,
26+
fig, axes = plt.subplots(figsize=[8.0, 7.5], ncols=2, nrows=2)
27+
28+
axes[0, 0].imshow(big_im, interpolation='none')
29+
axes[0, 1].imshow(big_im, interpolation='nearest')
30+
axes[1, 0].imshow(small_im, interpolation='none')
31+
axes[1, 1].imshow(small_im, interpolation='nearest')
32+
fig.subplots_adjust(left=0.24, wspace=0.2, hspace=0.1,
3633
bottom=0.05, top=0.86)
3734

3835
# Label the rows and columns of the table
@@ -60,6 +57,6 @@
6057
pdf_im_path = cbook.get_sample_data('None_vs_nearest-pdf.png')
6158
pdf_im = plt.imread(pdf_im_path)
6259
fig2 = plt.figure(figsize=[8.0, 7.5])
63-
plt.figimage(pdf_im)
60+
fig2.figimage(pdf_im)
6461

6562
plt.show()

examples/images_contours_and_fields/streamplot_demo_masking.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
U = np.ma.array(U, mask=mask)
1919
U[:20, :20] = np.nan
2020

21-
plt.streamplot(X, Y, U, V, color='r')
21+
fig, ax = plt.subplots()
22+
ax.streamplot(X, Y, U, V, color='r')
2223

23-
plt.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5,
24-
interpolation='nearest', cmap=plt.cm.gray)
24+
ax.imshow(~mask, extent=(-w, w, -w, w), alpha=0.5,
25+
interpolation='nearest', cmap=plt.cm.gray)
2526

2627
plt.show()

0 commit comments

Comments
 (0)
0