File tree 2 files changed +34
-0
lines changed
2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -690,6 +690,17 @@ 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 ) or self .name != other .name or
695
+ self .colorbar_extend != other .colorbar_extend ):
696
+ return False
697
+ # To compare lookup tables the Colormaps have to be initialized
698
+ if not self ._isinit :
699
+ self ._init ()
700
+ if not other ._isinit :
701
+ other ._init ()
702
+ return np .array_equal (self ._lut , other ._lut )
703
+
693
704
def get_bad (self ):
694
705
"""Get the color for masked values."""
695
706
if not self ._isinit :
Original file line number Diff line number Diff line change @@ -162,6 +162,29 @@ 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
+ # Test different names are not equal
179
+ cm_copy = cmap .copy ()
180
+ cm_copy .name = "Test"
181
+ assert cm_copy != cmap
182
+ # Test colorbar extends
183
+ cm_copy = cmap .copy ()
184
+ cm_copy .colorbar_extend = not cmap .colorbar_extend
185
+ assert cm_copy != cmap
186
+
187
+
165
188
def test_colormap_endian ():
166
189
"""
167
190
GitHub issue #1005: a bug in putmask caused erroneous
You can’t perform that action at this time.
0 commit comments