Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0c76f2e

Browse files
authored
Merge pull request #18792 from timhoffm/cmap-cleanup
DOC: Cmap cleanup
2 parents 2e75ed0 + 55bba4b commit 0c76f2e

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

doc/users/next_whats_new/2019-06-28-AL.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
`.Colormap.set_extremes` and `.Colormap.with_extremes`
2-
``````````````````````````````````````````````````````
1+
``Colormap.set_extremes`` and ``Colormap.with_extremes``
2+
````````````````````````````````````````````````````````
33

44
Because the `.Colormap.set_bad`, `.Colormap.set_under` and `.Colormap.set_over`
55
methods modify the colormap in place, the user must be careful to first make a

examples/color/custom_cmap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@
9090
fig.subplots_adjust(left=0.02, bottom=0.06, right=0.95, top=0.94, wspace=0.05)
9191
for n_bin, ax in zip(n_bins, axs.ravel()):
9292
# Create the colormap
93-
cm = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bin)
93+
cmap = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bin)
9494
# Fewer bins will result in "coarser" colomap interpolation
95-
im = ax.imshow(Z, origin='lower', cmap=cm)
95+
im = ax.imshow(Z, origin='lower', cmap=cmap)
9696
ax.set_title("N bins: %s" % n_bin)
9797
fig.colorbar(im, ax=ax)
9898

examples/subplots_axes_and_figures/colorbar_placement.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
np.random.seed(19680801)
1717

1818
fig, axs = plt.subplots(2, 2)
19-
cm = ['RdBu_r', 'viridis']
19+
cmaps = ['RdBu_r', 'viridis']
2020
for col in range(2):
2121
for row in range(2):
2222
ax = axs[row, col]
2323
pcm = ax.pcolormesh(np.random.random((20, 20)) * (col + 1),
24-
cmap=cm[col])
24+
cmap=cmaps[col])
2525
fig.colorbar(pcm, ax=ax)
2626
plt.show()
2727

@@ -31,12 +31,12 @@
3131
# `.Figure.colorbar` with a list of axes instead of a single axes.
3232

3333
fig, axs = plt.subplots(2, 2)
34-
cm = ['RdBu_r', 'viridis']
34+
cmaps = ['RdBu_r', 'viridis']
3535
for col in range(2):
3636
for row in range(2):
3737
ax = axs[row, col]
3838
pcm = ax.pcolormesh(np.random.random((20, 20)) * (col + 1),
39-
cmap=cm[col])
39+
cmap=cmaps[col])
4040
fig.colorbar(pcm, ax=axs[:, col], shrink=0.6)
4141
plt.show()
4242

lib/matplotlib/tests/test_colors.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,22 +132,22 @@ def test_colormap_dict_deprecate():
132132
# Make sure we warn on get and set access into cmap_d
133133
with pytest.warns(cbook.MatplotlibDeprecationWarning,
134134
match="The global colormaps dictionary is no longer"):
135-
cm = plt.cm.cmap_d['viridis']
135+
cmap = plt.cm.cmap_d['viridis']
136136

137137
with pytest.warns(cbook.MatplotlibDeprecationWarning,
138138
match="The global colormaps dictionary is no longer"):
139-
plt.cm.cmap_d['test'] = cm
139+
plt.cm.cmap_d['test'] = cmap
140140

141141

142142
def test_colormap_copy():
143-
cm = plt.cm.Reds
144-
cm_copy = copy.copy(cm)
143+
cmap = plt.cm.Reds
144+
copied_cmap = copy.copy(cmap)
145145
with np.errstate(invalid='ignore'):
146-
ret1 = cm_copy([-1, 0, .5, 1, np.nan, np.inf])
147-
cm2 = copy.copy(cm_copy)
148-
cm2.set_bad('g')
146+
ret1 = copied_cmap([-1, 0, .5, 1, np.nan, np.inf])
147+
cmap2 = copy.copy(copied_cmap)
148+
cmap2.set_bad('g')
149149
with np.errstate(invalid='ignore'):
150-
ret2 = cm_copy([-1, 0, .5, 1, np.nan, np.inf])
150+
ret2 = copied_cmap([-1, 0, .5, 1, np.nan, np.inf])
151151
assert_array_equal(ret1, ret2)
152152

153153

lib/matplotlib/tests/test_image.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ def test_imshow_endianess():
865865
remove_text=True, style='mpl20')
866866
def test_imshow_masked_interpolation():
867867

868-
cm = plt.get_cmap('viridis').with_extremes(over='r', under='b', bad='k')
868+
cmap = plt.get_cmap('viridis').with_extremes(over='r', under='b', bad='k')
869869

870870
N = 20
871871
n = colors.Normalize(vmin=0, vmax=N*N-1)
@@ -892,7 +892,7 @@ def test_imshow_masked_interpolation():
892892

893893
for interp, ax in zip(interps, ax_grid.ravel()):
894894
ax.set_title(interp)
895-
ax.imshow(data, norm=n, cmap=cm, interpolation=interp)
895+
ax.imshow(data, norm=n, cmap=cmap, interpolation=interp)
896896
ax.axis('off')
897897

898898

@@ -1213,8 +1213,8 @@ def test_huge_range_log(fig_test, fig_ref):
12131213
data = np.full((5, 5), -1, dtype=np.float64)
12141214
data[0:2, :] = 1000
12151215

1216-
cm = copy(plt.get_cmap('viridis'))
1217-
cm.set_under('w')
1216+
cmap = copy(plt.get_cmap('viridis'))
1217+
cmap.set_under('w')
12181218
ax = fig_ref.subplots()
12191219
im = ax.imshow(data, norm=colors.Normalize(vmin=100, vmax=data.max()),
1220-
interpolation='nearest', cmap=cm)
1220+
interpolation='nearest', cmap=cmap)

0 commit comments

Comments
 (0)