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 7e0cd35

Browse filesBrowse files
phobson
authored andcommitted
DOC: switch to OO interface in color + image/contour examples
1 parent 3a41957 commit 7e0cd35
Copy full SHA for 7e0cd35

File tree

Expand file treeCollapse file tree

6 files changed

+20
-20
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+20
-20
lines changed

‎examples/color/color_cycle_demo.py

Copy file name to clipboardExpand all lines: examples/color/color_cycle_demo.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/contourf_log.py
+3-2Lines 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(cs)
4546

4647
plt.show()

‎examples/images_contours_and_fields/image_demo.py

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/image_demo.py
+3-2Lines 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

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/image_demo_clip_path.py
+1-1Lines 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

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/interpolation_none_vs_nearest.py
+8-11Lines 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

Copy file name to clipboardExpand all lines: examples/images_contours_and_fields/streamplot_demo_masking.py
+4-3Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.