File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -690,6 +690,16 @@ def __copy__(self):
690690 cmapobject ._global = False
691691 return cmapobject
692692
693+ def __eq__ (self , other ):
694+ if isinstance (other , Colormap ):
695+ # To compare lookup tables the Colormaps have to be initialized
696+ if not self ._isinit :
697+ self ._init ()
698+ if not other ._isinit :
699+ other ._init ()
700+ return np .array_equal (self ._lut , other ._lut )
701+ return False
702+
693703 def get_bad (self ):
694704 """Get the color for masked values."""
695705 if not self ._isinit :
Original file line number Diff line number Diff line change @@ -162,6 +162,21 @@ def test_colormap_copy():
162162 assert_array_equal (ret1 , ret2 )
163163
164164
165+ def test_colormap_equals ():
166+ cmap = plt .get_cmap ("plasma" )
167+ cm_copy = cmap .copy ()
168+ # different object id's
169+ assert cm_copy is not cmap
170+ # But the same data should be equal
171+ assert cm_copy == cmap
172+ # Change the copy
173+ cm_copy .set_bad ('y' )
174+ assert cm_copy != cmap
175+ # Make sure we can compare different sizes without failure
176+ cm_copy ._lut = cm_copy ._lut [:10 , :]
177+ assert cm_copy != cmap
178+
179+
165180def test_colormap_endian ():
166181 """
167182 GitHub issue #1005: a bug in putmask caused erroneous
You can’t perform that action at this time.
0 commit comments