8000 Merge pull request #29028 from Kaustbh/issue3 · matplotlib/matplotlib@9cc62f1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9cc62f1

Browse files
authored
Merge pull request #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()

galleries/examples/images_contours_and_fields/shading_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def main():
2525
dem = cbook.get_sample_data('jacksboro_fault_dem.npz')
2626
elev = dem['elevation']
2727

28-
fig = compare(z, plt.cm.copper)
28+
fig = compare(z, plt.colormaps["copper"])
2929
fig.suptitle('HSV Blending Looks Best with Smooth Surfaces', y=0.95)
3030

31-
fig = compare(elev, plt.cm.gist_earth, ve=0.05)
31+
fig = compare(elev, plt.colormaps["gist_earth"], ve=0.05)
3232
fig.suptitle('Overlay Blending Looks Best with Rough Surfaces', y=0.95)
3333

3434
plt.show()

galleries/examples/lines_bars_and_markers/gradient_bar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,15 @@ def gradient_bar(ax, x, y, width=0.5, bottom=0):
5656
for left, top in zip(x, y):
5757
right = left + width
5858
gradient_image(ax, extent=(left, right, bottom, top),
59-
cmap=plt.cm.Blues_r, cmap_range=(0, 0.8))
59+
cmap="Blues_r", cmap_range=(0, 0.8))
6060

6161

6262
fig, ax = plt.subplots()
6363
ax.set(xlim=(0, 10), ylim=(0, 1))
6464

6565
# background image
6666
gradient_image(ax, direction=1, extent=(0, 1, 0, 1), transform=ax.transAxes,
67-
cmap=plt.cm.RdYlGn, cmap_range=(0.2, 0.8), alpha=0.5)
67+
cmap="RdYlGn", cmap_range=(0.2, 0.8), alpha=0.5)
6868

6969
N = 10
7070
x = np.arange(N) + 0.15

galleries/examples/lines_bars_and_markers/multivariate_marker_plot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
t = Affine2D().scale(skill).rotate_deg(takeoff)
4040
m = MarkerStyle(SUCCESS_SYMBOLS[mood], transform=t)
4141
ax.plot(pos[0], pos[1], marker=m, color=cmap(thrust))
42-
fig.colorbar(plt.cm.ScalarMappable(norm=Normalize(0, 1), cmap=cmap),
42+
fig.colorbar(plt.cm.ScalarMappable(norm=Normalize(0, 1), cmap="plasma"),
4343
ax=ax, label="Normalized Thrust [a.u.]")
4444
ax.set_xlabel("X position [m]")
4545
ax.set_ylabel("Y position [m]")

galleries/examples/misc/contour_manual.py

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

99
import matplotlib.pyplot as plt
1010

11-
import matplotlib.cm as cm
1211
from matplotlib.contour import ContourSet
1312
from matplotlib.path import Path
1413

@@ -30,12 +29,12 @@
3029
fig, ax = plt.subplots()
3130

3231
# Filled contours using filled=True.
33-
cs = ContourSet(ax, [0, 1, 2], [filled01, filled1 97AE 2], filled=True, cmap=cm.bone)
32+
cs = ContourSet(ax, [0, 1, 2], [filled01, filled12], filled=True, cmap="bone")
3433
cbar = fig.colorbar(cs)
3534

3635
# Contour lines (non-filled).
3736
lines = ContourSet(
38-
ax, [0, 1, 2], [lines0, lines1, lines2], cmap=cm.cool, linewidths=3)
37+
ax, [0, 1, 2], [lines0, lines1, lines2], cmap="cool", linewidths=3)
3938
cbar.add_lines(lines)
4039

4140
ax.set(xlim=(-0.5, 3.5), ylim=(-0.5, 4.5),

galleries/examples/misc/demo_agg_filter.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import numpy as np
1515

1616
from matplotlib.artist import Artist
17-
import matplotlib.cm as cm
1817
from matplotlib.colors import LightSource
1918
import matplotlib.transforms as mtransforms
2019

@@ -179,7 +178,7 @@ def filtered_text(ax):
179178

180179
# draw
181180
ax.imshow(Z, interpolation='bilinear', origin='lower',
182-
cmap=cm.gray, extent=(-3, 3, -2, 2), aspect='auto')
181+
cmap="gray", extent=(-3, 3, -2, 2), aspect='auto')
183182
levels = np.arange(-1.2, 1.6, 0.2)
184183
CS = ax.contour(Z, levels,
185184
origin='lower',

galleries/examples/misc/hyperlinks_sgskip.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
# %%
1917

2018
fig = plt.figure()
@@ -32,7 +30,7 @@
3230
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
3331
Z = (Z1 - Z2) * 2
3432

35-
im = plt.imshow(Z, interpolation='bilinear', cmap=cm.gray,
33+
im = plt.imshow(Z, interpolation='bilinear', cmap="gray",
3634
origin='lower', extent=(-3, 3, -3, 3))
3735

3836
im.set_url('https://www.google.com/')

galleries/examples/misc/table_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
value_increment = 1000
2222

2323
# Get some pastel shades for the colors
24-
colors = plt.cm.BuPu(np.linspace(0, 0.5, len(rows)))
24+
colors = plt.colormaps["BuPu"](np.linspace(0, 0.5, len(rows)))
2525
n_rows = len(data)
2626

2727
index = np.arange(len(columns)) + 0.3

galleries/examples/mplot3d/contour3d.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,12 @@
99

1010
import matplotlib.pyplot as plt
1111

12-
from matplotlib import cm
1312
from mpl_toolkits.mplot3d import axes3d
1413

1514
ax = plt.figure().add_subplot(projection='3d')
1615
X, Y, Z = axes3d.get_test_data(0.05)
1716

18-
ax.contour(X, Y, Z, cmap=cm.coolwarm) # Plot contour curves
17+
ax.contour(X, Y, Z, cmap="coolwarm") # Plot contour curves
1918

2019
plt.show()
2120

galleries/examples/mplot3d/contour3d_2.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99

1010
import matplotlib.pyplot as plt
1111

12-
from matplotlib import cm
1312
from mpl_toolkits.mplot3d import axes3d
1413

1514
ax = plt.figure().add_subplot(projection='3d')
1615
X, Y, Z = axes3d.get_test_data(0.05)
17-
ax.contour(X, Y, Z, extend3d=True, cmap=cm.coolwarm)
16+
ax.contour(X, Y, Z, extend3d=True, cmap="coolwarm")
1817

1918
plt.show()
2019

galleries/examples/mplot3d/contourf3d.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@
1212

1313
import matplotlib.pyplot as plt
1414

15-
from matplotlib import cm
1615
from mpl_toolkits.mplot3d import axes3d
1716

1817
ax = plt.figure().add_subplot(projection='3d')
1918
X, Y, Z = axes3d.get_test_data(0.05)
20-
ax.contourf(X, Y, Z, cmap=cm.coolwarm)
19+
ax.contourf(X, Y, Z, cmap="coolwarm")
2120

2221
plt.show()
2322

galleries/examples/mplot3d/custom_shaded_3d_surface.py

Lines changed: 2 additions & 2 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import matplotlib.pyplot as plt
1010
import numpy as np
1111

12-
from matplotlib import cbook, cm
12+
from matplotlib import cbook
1313
from matplotlib.colors import LightSource
1414

1515
# Load and format data
@@ -29,7 +29,7 @@
2929
ls = LightSource(270, 45)
3030
# To use a custom hillshading mode, override the built-in shading and pass
3131
# in the rgb colors of the shaded surface calculated from "shade".
32-
rgb = ls.shade(z, cmap=cm.gist_earth, vert_exag=0.1, blend_mode='soft')
32+
rgb = ls.shade(z, cmap=plt.colormaps["gist_earth"], vert_exag=0.1, blend_mode='soft')
3333
surf = ax.plot_surface(x, y, z, rstride=1, cstride=1, facecolors=rgb,
3434
linewidth=0, antialiased=False, shade=False)
3535

galleries/examples/mplot3d/subplot3d.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import matplotlib.pyplot as plt
1010
import numpy as np
1111

12-
from matplotlib import cm
1312
from mpl_toolkits.mplot3d.axes3d import get_test_data
1413

1514
# set up a figure twice as wide as it is tall
@@ -27,7 +26,7 @@
2726
X, Y = np.meshgrid(X, Y)
2827
R = np.sqrt(X**2 + Y**2)
2928
Z = np.sin(R)
30-
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm,
29+
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap="coolwarm",
3130
linewidth=0, antialiased=False)
3231
ax.set_zlim(-1.01, 1.01)
3332
fig.colorbar(surf, shrink=0.5, aspect=10)

galleries/examples/mplot3d/surface3d.py

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

16-
from matplotlib import cm
1716
from matplotlib.ticker import LinearLocator
1817

1918
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
@@ -26,7 +25,7 @@
2625
Z = np.sin(R)
2726

2827
# Plot the surface.
29-
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
28+
surf = ax.plot_surface(X, Y, Z, cmap="coolwarm",
3029
linewidth=0, antialiased=False)
3130

3231
# Customize the z axis.

galleries/examples/mplot3d/surface3d_radial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
X, Y = R*np.cos(P), R*np.sin(P)
2727

2828
# Plot the surface.
29-
ax.plot_surface(X, Y, Z, cmap=plt.cm.YlGnBu_r)
29+
ax.plot_surface(X, Y, Z, cmap="YlGnBu_r")
3030

3131
# Tweak the limits and add latex math labels.
3232
ax.set_zlim(0, 1)

galleries/examples/mplot3d/tricontour3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
< min_radius)
3838

3939
ax = plt.figure().add_subplot(projection='3d')
40-
ax.tricontour(triang, z, cmap=plt.cm.CMRmap)
40+
ax.tricontour(triang, z, cmap="CMRmap")
4141

4242
# Customize the view angle so it's easier to understand the plot.
4343
ax.view_init(elev=45.)

0 commit comments

Comments
 (0)
0