Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf94d64d

Browse files
committed
MAINT: Adding an equals method to colormaps
This adds an __eq__ method to Colormap to test the lookuptables for equality.
1 parentcb21d7d commitf94d64d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

‎lib/matplotlib/colors.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,16 @@ def __copy__(self):
690690
cmapobject._global=False
691691
returncmapobject
692692

693+
def__eq__(self,other):
694+
ifnotisinstance(other,Colormap):
695+
returnFalse
696+
# To compare lookup tables the Colormaps have to be initialized
697+
ifnotself._isinit:
698+
self._init()
699+
ifnotother._isinit:
700+
other._init()
701+
returnnp.array_equal(self._lut,other._lut)
702+
693703
defget_bad(self):
694704
"""Get the color for masked values."""
695705
ifnotself._isinit:

‎lib/matplotlib/tests/test_colors.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,21 @@ def test_colormap_copy():
162162
assert_array_equal(ret1,ret2)
163163

164164

165+
deftest_colormap_equals():
166+
cmap=plt.get_cmap("plasma")
167+
cm_copy=cmap.copy()
168+
# different object id's
169+
assertcm_copyisnotcmap
170+
# But the same data should be equal
171+
assertcm_copy==cmap
172+
# Change the copy
173+
cm_copy.set_bad('y')
174+
assertcm_copy!=cmap
175+
# Make sure we can compare different sizes without failure
176+
cm_copy._lut=cm_copy._lut[:10, :]
177+
assertcm_copy!=cmap
178+
179+
165180
deftest_colormap_endian():
166181
"""
167182
GitHub issue #1005: a bug in putmask caused erroneous

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp