Skip to content

Commit 9cc62f1

Browse files
authored
Merge pull request matplotlib#29028 from Kaustbh/issue3
Update colormap usage documentation to prioritize string colormap names
2 parents 48126ca + 191efce commit 9cc62f1

Some content is hidden

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

49 files changed

+89
-109
lines changed

doc/users/prev_whats_new/whats_new_3.10.0.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ colour maps version 8.0.1 (DOI: https://doi.org/10.5281/zenodo.1243862).
5656
img = np.sin(x*y)
5757

5858
_, ax = plt.subplots(1, 3)
59-
ax[0].imshow(img, cmap=plt.cm.berlin)
60-
ax[1].imshow(img, cmap=plt.cm.managua)
61-
ax[2].imshow(img, cmap=plt.cm.vanimo)
59+
ax[0].imshow(img, cmap="berlin")
60+
ax[1].imshow(img, cmap="managua")
61+
ax[2].imshow(img, cmap="vanimo")
6262

6363

6464

galleries/examples/axisartist/demo_curvelinear_grid2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def inv_tr(x, y):
4141
# itself (i.e., transData) is not affected by the given transform.
4242

4343
ax1.imshow(np.arange(25).reshape(5, 5),
44-
vmax=50, cmap=plt.cm.gray_r, origin="lower")
44+
vmax=50, cmap="gray_r", origin="lower")
4545

4646

4747
if __name__ == "__main__":

galleries/examples/images_contours_and_fields/contour_demo.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import matplotlib.pyplot as plt
1414
import numpy as np
1515

16-
import matplotlib.cm as cm
17-
1816
delta = 0.025
1917
x = np.arange(-3.0, 3.0, delta)
2018
y = np.arange(-2.0, 2.0, delta)
@@ -79,7 +77,7 @@
7977

8078
fig, ax = plt.subplots()
8179
im = ax.imshow(Z, interpolation='bilinear', origin='lower',
82-
cmap=cm.gray, extent=(-3, 3, -2, 2))
80+
cmap="gray", extent=(-3, 3, -2, 2))
8381
levels = np.arange(-1.2, 1.6, 0.2)
8482
CS = ax.contour(Z, levels, origin='lower', cmap='flag', extend='both',
8583
linewidths=2, extent=(-3, 3, -2, 2))

galleries/examples/images_contours_and_fields/contour_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
levels = np.arange(-2.0, 1.601, 0.4)
3636

3737
norm = cm.colors.Normalize(vmax=abs(Z).max(), vmin=-abs(Z).max())
38-
cmap = cm.PRGn
38+
cmap = plt.colormaps["PRGn"]
3939

4040
fig, _axs = plt.subplots(nrows=2, ncols=2)
4141
fig.subplots_adjust(hspace=0.3)

galleries/examples/images_contours_and_fields/contourf_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# for purposes of illustration.
4040

4141
fig1, ax2 = plt.subplots(layout='constrained')
42-
CS = ax2.contourf(X, Y, Z, 10, cmap=plt.cm.bone)
42+
CS = ax2.contourf(X, Y, Z, 10, cmap="bone")
4343

4444
# Note that in the following, we explicitly pass in a subset of the contour
4545
# levels used for the filled contours. Alternatively, we could pass in

galleries/examples/images_contours_and_fields/contourf_log.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111
from numpy import ma
1212

13-
from matplotlib import cm, ticker
13+
from matplotlib import ticker
1414

1515
N = 100
1616
x = np.linspace(-3.0, 3.0, N)
@@ -36,7 +36,7 @@
3636
# Automatic selection of levels works; setting the
3737
# log locator tells contourf to use a log scale:
3838
fig, ax = plt.subplots()
39-
cs = ax.contourf(X, Y, z, locator=ticker.LogLocator(), cmap=cm.PuBu_r)
39+
cs = ax.contourf(X, Y, z, locator=ticker.LogLocator(), cmap="PuBu_r")
4040

4141
# Alternatively, you can manually set the levels
4242
# and the norm:

galleries/examples/images_contours_and_fields/image_demo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import numpy as np
1313

1414
import matplotlib.cbook as cbook
15-
import matplotlib.cm as cm
1615
from matplotlib.patches import PathPatch
1716
from matplotlib.path import Path
1817

@@ -30,7 +29,7 @@
3029
Z = (Z1 - Z2) * 2
3130

3231
fig, ax = plt.subplots()
33-
im = ax.imshow(Z, interpolation='bilinear', cmap=cm.RdYlBu,
32+
im = ax.imshow(Z, interpolation='bilinear', cmap="RdYlBu",
3433
origin='lower', extent=[-3, 3, -3, 3],
3534
vmax=abs(Z).max(), vmin=-abs(Z).max())
3635

@@ -58,7 +57,7 @@
5857
ax['hopper'].imshow(image)
5958
ax['hopper'].axis('off') # clear x-axis and y-axis
6059

61-
im = ax['mri'].imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent)
60+
im = ax['mri'].imshow(A, cmap="hot", origin='upper', extent=extent)
6261

6362
markers = [(15.9, 14.5), (16.8, 15)]
6463
x, y = zip(*markers)
@@ -163,7 +162,7 @@
163162
fig, ax = plt.subplots()
164163
ax.add_patch(patch)
165164

166-
im = ax.imshow(Z, interpolation='bilinear', cmap=cm.gray,
165+
im = ax.imshow(Z, interpolation='bilinear', cmap="gray",
167166
origin='lower', extent=[-3, 3, -3, 3],
168167
clip_path=patch, clip_on=True)
169168
im.set_clip_path(patch)

galleries/examples/images_contours_and_fields/image_masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
Z = (Z1 - Z2) * 2
2626

2727
# Set up a colormap:
28-
palette = plt.cm.gray.with_extremes(over='r', under='g', bad='b')
28+
palette = plt.colormaps["gray"].with_extremes(over='r', under='g', bad='b')
2929
# Alternatively, we could use
3030
# palette.set_bad(alpha = 0.0)
3131
# to make the bad region transparent. This is the default.

galleries/examples/images_contours_and_fields/image_nonuniform.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import matplotlib.pyplot as plt
1212
import numpy as np
1313

14-
from matplotlib import cm
1514
from matplotlib.image import NonUniformImage
1615

1716
interp = 'nearest'
@@ -30,7 +29,7 @@
3029
fig.suptitle('NonUniformImage class', fontsize='large')
3130
ax = axs[0, 0]
3231
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),
33-
cmap=cm.Purples)
32+
cmap="Purples")
3433
im.set_data(x, y, z)
3534
ax.add_image(im)
3635
ax.set_xlim(-4, 4)
@@ -39,7 +38,7 @@
3938

4039
ax = axs[0, 1]
4140
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),
42-
cmap=cm.Purples)
41+
cmap="Purples")
4342
im.set_data(x2, y, z)
4443
ax.add_image(im)
4544
ax.set_xlim(-64, 64)
@@ -50,7 +49,7 @@
5049

5150
ax = axs[1, 0]
5251
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),
53-
cmap=cm.Purples)
52+
cmap="Purples")
5453
im.set_data(x, y, z)
5554
ax.add_image(im)
5655
ax.set_xlim(-4, 4)
@@ -59,7 +58,7 @@
5958

6059
ax = axs[1, 1]
6160
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),
62-
cmap=cm.Purples)
61+
cmap="Purples")
6362
im.set_data(x2, y, z)
6463
ax.add_image(im)
6564
ax.set_xlim(-64, 64)

galleries/examples/images_contours_and_fields/layer_images.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ def func3(x, y):
3131
fig = plt.figure(frameon=False)
3232

3333
Z1 = np.add.outer(range(8), range(8)) % 2 # chessboard
34-
im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
34+
im1 = plt.imshow(Z1, cmap="gray", interpolation='nearest',
3535
extent=extent)
3636

3737
Z2 = func3(X, Y)
3838

39-
im2 = plt.imshow(Z2, cmap=plt.cm.viridis, alpha=.9, interpolation='bilinear',
39+
im2 = plt.imshow(Z2, cmap="viridis", alpha=.9, interpolation='bilinear',
4040
extent=extent)
4141

4242
plt.show()

0 commit comments

Comments
 (0)