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
10 changes: 10 additions & 0 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ def __call__(self, X, alpha=None, bytes=False):
rgba = tuple(rgba[0, :])
return rgba

def __copy__(self):
"""Create new object with the same class, update attributes
"""
cls = self.__class__
cmapobject = cls.__new__(cls)
cmapobject.__dict__.update(self.__dict__)
if self._isinit:
cmapobject._lut = np.copy(self._lut)
return cmapobject

def set_bad(self, color='k', alpha=None):
"""Set color to be used for masked values.
"""
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import (absolute_import, division, print_function,
unicode_literals)

import copy
import six
import itertools
import warnings
Expand Down Expand Up @@ -44,6 +45,18 @@ def test_resample():
assert_array_almost_equal(lc3([0, 0.5, 1]), expected)


def test_colormap_copy():
cm = plt.cm.Reds
cm_copy = copy.copy(cm)
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')
with np.errstate(invalid='ignore'):
ret2 = cm_copy([-1, 0, .5, 1, np.nan, np.inf])
assert_array_equal(ret1, ret2)


def test_colormap_endian():
"""
Github issue #1005: a bug in putmask caused erroneous
Expand Down