Skip to content

Only do pchanged and set stale when value changes + doc consistency #26326

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 2 commits into from
Aug 9, 2023
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
52 changes: 29 additions & 23 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ def get_tightbbox(self, renderer=None):

Parameters
----------
renderer : `.RendererBase` subclass
renderer : `~matplotlib.backend_bases.RendererBase` subclass, optional
renderer that will be used to draw the figures (i.e.
``fig.canvas.get_renderer()``)

Expand Down Expand Up @@ -440,7 +440,7 @@ def set_transform(self, t):

Parameters
----------
t : `.Transform`
t : `~matplotlib.transforms.Transform`
"""
self._transform = t
self._transformSet = True
Expand Down Expand Up @@ -733,7 +733,7 @@ def set_figure(self, fig):

Parameters
----------
fig : `.Figure`
fig : `~matplotlib.figure.Figure`
"""
# if this is a no-op just return
if self.figure is fig:
Expand All @@ -757,15 +757,16 @@ def set_clip_box(self, clipbox):

Parameters
----------
clipbox : `.BboxBase` or None
Typically would be created from a `.TransformedBbox`. For
instance ``TransformedBbox(Bbox([[0, 0], [1, 1]]), ax.transAxes)``
is the default clipping for an artist added to an Axes.
clipbox : `~matplotlib.transforms.BboxBase` or None
Will typically be created from a `.TransformedBbox`. For instance,
``TransformedBbox(Bbox([[0, 0], [1, 1]]), ax.transAxes)`` is the default
clipping for an artist added to an Axes.

"""
self.clipbox = clipbox
self.pchanged()
self.stale = True
if clipbox != self.clipbox:
self.clipbox = clipbox
self.pchanged()
self.stale = True

def set_clip_path(self, path, transform=None):
"""
Expand Down Expand Up @@ -986,7 +987,7 @@ def draw(self, renderer):

Parameters
----------
renderer : `.RendererBase` subclass.
renderer : `~matplotlib.backend_bases.RendererBase` subclass.

Notes
-----
Expand All @@ -1010,9 +1011,10 @@ def set_alpha(self, alpha):
f'alpha must be numeric or None, not {type(alpha)}')
if alpha is not None and not (0 <= alpha <= 1):
raise ValueError(f'alpha ({alpha}) is outside 0-1 range')
self._alpha = alpha
self.pchanged()
self.stale = True
if alpha != self._alpha:
self._alpha = alpha
self.pchanged()
self.stale = True
Comment on lines +1016 to +1017
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a follow-up PR I wonder if we should move self.stale = True into the pchanged definition? It seems like every call to pchanged is followed by self.stale = True...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can for sure be a good idea.


def _set_alpha_for_array(self, alpha):
"""
Expand Down Expand Up @@ -1045,9 +1047,10 @@ def set_visible(self, b):
----------
b : bool
"""
self._visible = b
self.pchanged()
self.stale = True
if b != self._visible:
self._visible = b
self.pchanged()
self.stale = True

def set_animated(self, b):
"""
Expand Down Expand Up @@ -1095,9 +1098,11 @@ def set_label(self, s):
s : object
*s* will be converted to a string by calling `str`.
"""
self._label = str(s) if s is not None else None
self.pchanged()
self.stale = True
label = str(s) if s is not None else None
if label != self._label:
self._label = label
self.pchanged()
self.stale = True

def get_zorder(self):
"""Return the artist's zorder."""
Expand All @@ -1114,9 +1119,10 @@ def set_zorder(self, level):
"""
if level is None:
level = self.__class__.zorder
self.zorder = level
self.pchanged()
self.stale = True
if level != self.zorder:
self.zorder = level
self.pchanged()
self.stale = True

@property
def sticky_edges(self):
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __new__(cls, *args, **kwargs):
def __init__(self, kl, label=None):
self._callbacks = cbook.CallbackRegistry(signals=["pchanged"])
self._remove_method = None
self.set_label(label)
self._label = label

def remove(self):
for c in cbook.flatten(
Expand Down