diff --git a/doc/api/next_api_changes/removals/19552-GL.rst b/doc/api/next_api_changes/removals/19552-GL.rst new file mode 100644 index 000000000000..8606c64ebbf0 --- /dev/null +++ b/doc/api/next_api_changes/removals/19552-GL.rst @@ -0,0 +1,5 @@ +ScalarMappable update checkers +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``ScalarMappable.update_dict``, ``ScalarMappable.add_checker()``, and +``ScalarMappable.check_update()`` have been removed. A callback can +be registered in ``ScalarMappable.callbacksSM`` to be notified of updates. \ No newline at end of file diff --git a/lib/matplotlib/cm.py b/lib/matplotlib/cm.py index 667aed880efd..5326890ff1fd 100644 --- a/lib/matplotlib/cm.py +++ b/lib/matplotlib/cm.py @@ -264,7 +264,6 @@ def __init__(self, norm=None, cmap=None): #: The last colorbar associated with this ScalarMappable. May be None. self.colorbar = None self.callbacksSM = cbook.CallbackRegistry() - self._update_dict = {'array': False} def _scale_norm(self, norm, vmin, vmax): """ @@ -369,7 +368,6 @@ def set_array(self, A): A : ndarray or None """ self._A = A - self._update_dict['array'] = True def get_array(self): """Return the data array.""" @@ -476,30 +474,10 @@ def autoscale_None(self): self.norm.autoscale_None(self._A) self.changed() - def _add_checker(self, checker): - """ - Add an entry to a dictionary of boolean flags - that are set to True when the mappable is changed. - """ - self._update_dict[checker] = False - - def _check_update(self, checker): - """Return whether mappable has changed since the last check.""" - if self._update_dict[checker]: - self._update_dict[checker] = False - return True - return False - def changed(self): """ Call this whenever the mappable is changed to notify all the callbackSM listeners to the 'changed' signal. """ self.callbacksSM.process('changed', self) - for key in self._update_dict: - self._update_dict[key] = True self.stale = True - - update_dict = _api.deprecate_privatize_attribute("3.3") - add_checker = _api.deprecate_privatize_attribute("3.3") - check_update = _api.deprecate_privatize_attribute("3.3") diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index bb270b218e22..28f9b747556d 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -851,7 +851,6 @@ def set_alpha(self, alpha): supported. """ artist.Artist._set_alpha_for_array(self, alpha) - self._update_dict['array'] = True self._set_facecolor(self._original_facecolor) self._set_edgecolor(self._original_edgecolor) @@ -907,7 +906,7 @@ def update_scalarmappable(self): if not self._set_mappable_flags(): return # Allow possibility to call 'self.set_array(None)'. - if self._check_update("array") and self._A is not None: + if self._A is not None: # QuadMesh can map 2d arrays (but pcolormesh supplies 1d array) if self._A.ndim > 1 and not isinstance(self, QuadMesh): raise ValueError('Collections can only map rank 1 arrays') @@ -958,7 +957,6 @@ def update_from(self, other): self._A = other._A self.norm = other.norm self.cmap = other.cmap - # do we need to copy self._update_dict? -JJL self.stale = True diff --git a/lib/matplotlib/tests/test_collections.py b/lib/matplotlib/tests/test_collections.py index d11bab7a022b..e226ca131052 100644 --- a/lib/matplotlib/tests/test_collections.py +++ b/lib/matplotlib/tests/test_collections.py @@ -715,6 +715,22 @@ def test_quadmesh_set_array(): assert np.array_equal(coll.get_array(), np.ones(9)) +def test_quadmesh_vmin_vmax(): + # test when vmin/vmax on the norm changes, the quadmesh gets updated + fig, ax = plt.subplots() + cmap = mpl.cm.get_cmap('plasma') + norm = mpl.colors.Normalize(vmin=0, vmax=1) + coll = ax.pcolormesh([[1]], cmap=cmap, norm=norm) + fig.canvas.draw() + assert np.array_equal(coll.get_facecolors()[0, :], cmap(norm(1))) + + # Change the vmin/vmax of the norm so that the color is from + # the bottom of the colormap now + norm.vmin, norm.vmax = 1, 2 + fig.canvas.draw() + assert np.array_equal(coll.get_facecolors()[0, :], cmap(norm(1))) + + def test_quadmesh_alpha_array(): x = np.arange(4) y = np.arange(4) diff --git a/lib/mpl_toolkits/mplot3d/art3d.py b/lib/mpl_toolkits/mplot3d/art3d.py index 822ff79fcc24..8a169cbe7dbb 100644 --- a/lib/mpl_toolkits/mplot3d/art3d.py +++ b/lib/mpl_toolkits/mplot3d/art3d.py @@ -695,13 +695,11 @@ def _update_scalarmappable(sm): """ if sm._A is None: return - copy_state = sm._update_dict['array'] - ret = sm.update_scalarmappable() - if copy_state: - if sm._face_is_mapped: - sm._facecolor3d = sm._facecolors - elif sm._edge_is_mapped: # Should this be plain "if"? - sm._edgecolor3d = sm._edgecolors + sm.update_scalarmappable() + if sm._face_is_mapped: + sm._facecolor3d = sm._facecolors + elif sm._edge_is_mapped: # Should this be plain "if"? + sm._edgecolor3d = sm._edgecolors def patch_collection_2d_to_3d(col, zs=0, zdir='z', depthshade=True):
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: