8000 MNT: Remove scalarmappable private update attributes · matplotlib/matplotlib@ed6d92b · GitHub
[go: up one dir, main page]

Skip to content

Commit ed6d92b

Browse files
committed
MNT: Remove scalarmappable private update attributes
The updates to scalar mappable would only take effect if the array was updated. This meant that updating the vmin/vmax of the sm's norm would not be propagated to the drawn artists. This update removes the update checks from scalar mappable to calculate the colors regardless of updates to the array.
1 parent 91cb8a8 commit ed6d92b

File tree

5 files changed

+27
-32
lines changed

5 files changed

+27
-32
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ScalarMappable update checkers
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
``ScalarMappable.update_dict``, ``ScalarMappable.add_checker()``, and
4+
``ScalarMappable.check_update()`` have been removed. A callback can
5+
be registered in ``ScalarMappable.callbacksSM`` to be notified of updates.

lib/matplotlib/cm.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ def __init__(self, norm=None, cmap=None):
264264
#: The last colorbar associated with this ScalarMappable. May be None.
265265
self.colorbar = None
266266
self.callbacksSM = cbook.CallbackRegistry()
267-
self._update_dict = {'array': False}
268267

269268
def _scale_norm(self, norm, vmin, vmax):
270269
"""
@@ -369,7 +368,6 @@ def set_array(self, A):
369368
A : ndarray or None
370369
"""
371370
self._A = A
372-
self._update_dict['array'] = True
373371

374372
def get_array(self):
375373
"""Return the data array."""
@@ -476,30 +474,10 @@ def autoscale_None(self):
476474
self.norm.autoscale_None(self._A)
477475
self.changed()
478476

479-
def _add_checker(self, checker):
480-
"""
481-
Add an entry to a dictionary of boolean flags
482-
that are set to True when the mappable is changed.
483-
"""
484-
self._update_dict[checker] = False
485-
486-
def _check_update(self, checker):
487-
"""Return whether mappable has changed since the last check."""
488-
if self._update_dict[checker]:
489-
self._update_dict[checker] = False
490-
return True
491-
return False
492-
493477
def changed(self):
494478
"""
495479
Call this whenever the mappable is changed to notify all the
496480
callbackSM listeners to the 'changed' signal.
497481
"""
498482
self.callbacksSM.process('changed', self)
499-
for key in self._update_dict:
500-
self._update_dict[key] = True
501483
self.stale = True
502-
503-
update_dict = _api.deprecate_privatize_attribute("3.3")
504-
add_checker = _api.deprecate_privatize_attribute("3.3")
505-
check_update = _api.deprecate_privatize_attribute("3.3")

lib/matplotlib/collections.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,6 @@ def set_alpha(self, alpha):
851851
supported.
852852
"""
853853
artist.Artist._set_alpha_for_array(self, alpha)
854-
self._update_dict['array'] = True
855854
self._set_facecolor(self._original_facecolor)
856855
self._set_edgecolor(self._original_edgecolor)
857856

@@ -907,7 +906,7 @@ def update_scalarmappable(self):
907906
if not self._set_mappable_flags():
908907
return
909908
# Allow possibility to call 'self.set_array(None)'.
910-
if self._check_update("array") and self._A is not None:
909+
if self._A is not None:
911910
# QuadMesh can map 2d arrays (but pcolormesh supplies 1d array)
912911
if self._A.ndim > 1 and not isinstance(self, QuadMesh):
913912
raise ValueError('Collections can only map rank 1 arrays')
@@ -958,7 +957,6 @@ def update_from(self, other):
958957
self._A = other._A
959958
self.norm = other.norm
960959
self.cmap = other.cmap
961-
# do we need to copy self._update_dict? -JJL
962960
self.stale = True
963961

964962

lib/matplotlib/tests/test_collections.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,22 @@ def test_quadmesh_set_array():
715715
assert np.array_equal(coll.get_array(), np.ones(9))
716716

717717

718+
def test_quadmesh_vmin_vmax():
719+
# test when vmin/vmax on the norm changes, the quadmesh gets updated
720+
fig, ax = plt.subplots()
721+
cmap = mpl.cm.get_cmap('plasma')
722+
norm = mpl.colors.Normalize(vmin=0, vmax=1)
723+
coll = ax.pcolormesh([[1]], cmap=cmap, norm=norm)
724+
fig.canvas.draw()
725+
assert np.array_equal(coll.get_facecolors()[0, :], cmap(norm(1)))
726+
727+
# Change the vmin/vmax of the norm so that the color is from
728+
# the bottom of the colormap now
729+
norm.vmin, norm.vmax = 1, 2
730+
fig.canvas.draw()
731+
assert np.array_equal(coll.get_facecolors()[0, :], cmap(norm(1)))
732+
733+
718734
def test_quadmesh_alpha_array():
719735
x = np.arange(4)
720736
y = np.arange(4)

lib/mpl_toolkits/mplot3d/art3d.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -695,13 +695,11 @@ def _update_scalarmappable(sm):
695695
"""
696696
if sm._A is None:
697697
return
698-
copy_state = sm._update_dict['array']
699-
ret = sm.update_scalarmappable()
700-
if copy_state:
701-
if sm._face_is_mapped:
702-
sm._facecolor3d = sm._facecolors
703-
elif sm._edge_is_mapped: # Should this be plain "if"?
704-
sm._edgecolor3d = sm._edgecolors
698+
sm.update_scalarmappable()
699+
if sm._face_is_mapped:
700+
sm._facecolor3d = sm._facecolors
701+
elif sm._edge_is_mapped: # Should this be plain "if"?
702+
sm._edgecolor3d = sm._edgecolors
705703

706704

707705
def patch_collection_2d_to_3d(col, zs=0, zdir='z', depthshade=True):

0 commit comments

Comments
 (0)
0