File tree 2 files changed +25
-0
lines changed
2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -690,6 +690,16 @@ def __copy__(self):
690
690
cmapobject ._global = False
691
691
return cmapobject
692
692
693
+ def __eq__ (self , other ):
694
+ if not isinstance (other , Colormap ):
695
+ return False
696
+ # To compare lookup tables the Colormaps have to be initialized
697
+ if not self ._isinit :
698
+ self ._init ()
699
+ if not other ._isinit :
700
+ other ._init ()
701
+ return np .array_equal (self ._lut , other ._lut )
702
+
693
703
def get_bad (self ):
694
704
"""Get the color for masked values."""
695
705
if not self ._isinit :
Original file line number Diff line number Diff line change @@ -162,6 +162,21 @@ def test_colormap_copy():
162
162
assert_array_equal (ret1 , ret2 )
163
163
164
164
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
+
165
180
def test_colormap_endian ():
166
181
"""
167
182
GitHub issue #1005: a bug in putmask caused erroneous
You can’t perform that action at this time.
0 commit comments