Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Deprecate ScalarMappable.check_update and associated machinery. #17166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -450,3 +450,8 @@ needed.
The associated helper methods ``NavigationToolbar2.draw()`` and
``ToolViewsPositions.refresh_locators()`` are deprecated, and should be
replaced by calls to ``draw_idle()`` on the corresponding canvas.

`.ScalarMappable` checkers
~~~~~~~~~~~~~~~~~~~~~~~~~~
The ``add_checker`` and ``check_update`` methods and ``update_dict`` attribute
of `.ScalarMappable` are deprecated.
39 changes: 24 additions & 15 deletions lib/matplotlib/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ 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}
self._update_dict = {'array': False}

def _scale_norm(self, norm, vmin, vmax):
"""
Expand Down Expand Up @@ -279,7 +279,7 @@ def set_array(self, A):
A : ndarray
"""
self._A = A
self.update_dict['array'] = True
self._update_dict['array'] = True

def get_array(self):
"""Return the data array."""
Expand Down Expand Up @@ -386,30 +386,39 @@ def autoscale_None(self):
self.norm.autoscale_None(self._A)
self.changed()

def add_checker(self, checker):
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
self._update_dict[checker] = False

def check_update(self, checker):
"""
If mappable has changed since the last check,
return True; else return False
"""
if self.update_dict[checker]:
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
callbackSM listeners to the 'changed' signal.
"""
self.callbacksSM.process('changed', self)

for key in self.update_dict:
self.update_dict[key] = True
for key in self._update_dict:
self._update_dict[key] = True
self.stale = True

@cbook.deprecated("3.3")
@property
def update_dict(self):
return self._update_dict

@cbook.deprecated("3.3")
def add_checker(self, checker):
return self._add_checker(checker)

@cbook.deprecated("3.3")
def check_update(self, checker):
return self.check_update(checker)
6 changes: 3 additions & 3 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ def set_edgecolor(self, c):
def set_alpha(self, alpha):
# docstring inherited
super().set_alpha(alpha)
self.update_dict['array'] = True
self._update_dict['array'] = True
self._set_facecolor(self._original_facecolor)
self._set_edgecolor(self._original_edgecolor)

Expand All @@ -784,7 +784,7 @@ def update_scalarmappable(self):
return
if self._A.ndim > 1:
raise ValueError('Collections can only map rank 1 arrays')
if not self.check_update("array"):
if not self._check_update("array"):
return
if self._is_filled:
self._facecolors = self.to_rgba(self._A, self._alpha)
Expand Down Expand Up @@ -815,7 +815,7 @@ def update_from(self, other):
self._A = other._A
self.norm = other.norm
self.cmap = other.cmap
# self.update_dict = other.update_dict # do we need to copy this? -JJL
# do we need to copy self._update_dict? -JJL
self.stale = True


Expand Down