Cmap cleanup by timhoffm · Pull Request #18792 · matplotlib/matplotlib · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/users/next_whats_new/2019-06-28-AL.rst
4 changes: 2 additions & 2 deletions examples/color/custom_cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@
fig.subplots_adjust(left=0.02, bottom=0.06, right=0.95, top=0.94, wspace=0.05)
for n_bin, ax in zip(n_bins, axs.ravel()):
# Create the colormap
cm = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bin)
cmap = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bin)
# Fewer bins will result in "coarser" colomap interpolation
im = ax.imshow(Z, origin='lower', cmap=cm)
im = ax.imshow(Z, origin='lower', cmap=cmap)
ax.set_title("N bins: %s" % n_bin)
fig.colorbar(im, ax=ax)

Expand Down
8 changes: 4 additions & 4 deletions examples/subplots_axes_and_figures/colorbar_placement.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
np.random.seed(19680801)

fig, axs = plt.subplots(2, 2)
cm = ['RdBu_r', 'viridis']
cmaps = ['RdBu_r', 'viridis']
for col in range(2):
for row in range(2):
ax = axs[row, col]
pcm = ax.pcolormesh(np.random.random((20, 20)) * (col + 1),
cmap=cm[col])
cmap=cmaps[col])
fig.colorbar(pcm, ax=ax)
plt.show()

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

fig, axs = plt.subplots(2, 2)
cm = ['RdBu_r', 'viridis']
cmaps = ['RdBu_r', 'viridis']
for col in range(2):
for row in range(2):
ax = axs[row, col]
pcm = ax.pcolormesh(np.random.random((20, 20)) * (col + 1),
cmap=cm[col])
cmap=cmaps[col])
fig.colorbar(pcm, ax=axs[:, col], shrink=0.6)
plt.show()

Expand Down
16 changes: 8 additions & 8 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,22 +132,22 @@ def test_colormap_dict_deprecate():
# Make sure we warn on get and set access into cmap_d
with pytest.warns(cbook.MatplotlibDeprecationWarning,
match="The global colormaps dictionary is no longer"):
cm = plt.cm.cmap_d['viridis']
cmap = plt.cm.cmap_d['viridis']

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


def test_colormap_copy():
cm = plt.cm.Reds
cm_copy = copy.copy(cm)
cmap = plt.cm.Reds
copied_cmap = copy.copy(cmap)
with np.errstate(invalid='ignore'):
ret1 = cm_copy([-1, 0, .5, 1, np.nan, np.inf])
cm2 = copy.copy(cm_copy)
cm2.set_bad('g')
ret1 = copied_cmap([-1, 0, .5, 1, np.nan, np.inf])
cmap2 = copy.copy(copied_cmap)
cmap2.set_bad('g')
with np.errstate(invalid='ignore'):
ret2 = cm_copy([-1, 0, .5, 1, np.nan, np.inf])
ret2 = copied_cmap([-1, 0, .5, 1, np.nan, np.inf])
assert_array_equal(ret1, ret2)


Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/tests/test_image.py