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 f76bdcb

Browse filesBrowse files
authored
Merge pull request #26658 from meeseeksmachine/auto-backport-of-pr-26608-on-v3.8.x
Backport PR #26608 on branch v3.8.x (Removed unnecessary origin keywords)
2 parents c991a46 + 64509fc commit f76bdcb
Copy full SHA for f76bdcb

File tree

1 file changed

+23
-13
lines changed
Filter options

1 file changed

+23
-13
lines changed

‎galleries/examples/images_contours_and_fields/contourf_demo.py

Copy file name to clipboardExpand all lines: galleries/examples/images_contours_and_fields/contourf_demo.py
+23-13Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010

11-
origin = 'lower'
12-
1311
delta = 0.025
1412

1513
x = y = np.arange(-3.0, 3.01, delta)
@@ -41,14 +39,14 @@
4139
# for purposes of illustration.
4240

4341
fig1, ax2 = plt.subplots(layout='constrained')
44-
CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone, origin=origin)
42+
CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone)
4543

4644
# Note that in the following, we explicitly pass in a subset of the contour
4745
# levels used for the filled contours. Alternatively, we could pass in
4846
# additional levels to provide extra resolution, or leave out the *levels*
4947
# keyword argument to use all of the original levels.
5048

51-
CS2 = ax2.contour(CS, levels=CS.levels[::2], colors='r', origin=origin)
49+
CS2 = ax2.contour(CS, levels=CS.levels[::2], colors='r')
5250

5351
ax2.set_title('Nonsense (3 masked regions)')
5452
ax2.set_xlabel('word length anomaly')
@@ -68,20 +66,14 @@
6866

6967
fig2, ax2 = plt.subplots(layout='constrained')
7068
levels = [-1.5, -1, -0.5, 0, 0.5, 1]
71-
CS3 = ax2.contourf(X, Y, Z, levels,
72-
colors=('r', 'g', 'b'),
73-
origin=origin,
74-
extend='both')
69+
CS3 = ax2.contourf(X, Y, Z, levels, colors=('r', 'g', 'b'), extend='both')
7570
# Our data range extends outside the range of levels; make
7671
# data below the lowest contour level yellow, and above the
7772
# highest level cyan:
7873
CS3.cmap.set_under('yellow')
7974
CS3.cmap.set_over('cyan')
8075

81-
CS4 = ax2.contour(X, Y, Z, levels,
82-
colors=('k',),
83-
linewidths=(3,),
84-
origin=origin)
76+
CS4 = ax2.contour(X, Y, Z, levels, colors=('k',), linewidths=(3,))
8577
ax2.set_title('Listed colors (3 masked regions)')
8678
ax2.clabel(CS4, fmt='%2.1f', colors='w', fontsize=14)
8779

@@ -104,13 +96,31 @@
10496
fig, axs = plt.subplots(2, 2, layout="constrained")
10597

10698
for ax, extend in zip(axs.flat, extends):
107-
cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend, origin=origin)
99+
cs = ax.contourf(X, Y, Z, levels, cmap=cmap, extend=extend)
108100
fig.colorbar(cs, ax=ax, shrink=0.9)
109101
ax.set_title("extend = %s" % extend)
110102
ax.locator_params(nbins=4)
111103

112104
plt.show()
113105

106+
# %%
107+
# Orient contour plots using the origin keyword
108+
# ---------------------------------------------
109+
# This code demonstrates orienting contour plot data using the "origin" keyword
110+
111+
x = np.arange(1, 10)
112+
y = x.reshape(-1, 1)
113+
h = x * y
114+
115+
fig, (ax1, ax2) = plt.subplots(ncols=2)
116+
117+
ax1.set_title("origin='upper'")
118+
ax2.set_title("origin='lower'")
119+
ax1.contourf(h, levels=np.arange(5, 70, 5), extend='both', origin="upper")
120+
ax2.contourf(h, levels=np.arange(5, 70, 5), extend='both', origin="lower")
121+
122+
plt.show()
123+
114124
# %%
115125
#
116126
# .. admonition:: References

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.