Skip to content

Commit 87098e3

Browse files
committed
Only do pchanged and set stale when value changes + doc consistency
1 parent c0d9c98 commit 87098e3

23 files changed

+74
-68
lines changed

lib/matplotlib/_constrained_layout.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ def do_constrained_layout(fig, h_pad, w_pad,
7272
fig : Figure
7373
``Figure`` instance to do the layout in.
7474
75-
renderer : Renderer
76-
Renderer to use.
77-
7875
h_pad, w_pad : float
7976
Padding around the axes elements in figure-normalized units.
8077
@@ -675,7 +672,7 @@ def reposition_colorbar(layoutgrids, cbax, renderer, *, offset=None):
675672
cbax : Axes
676673
Axes for the colorbar
677674
678-
renderer :
675+
renderer : `~matplotlib.backend_bases.RendererBase` subclass
679676
w_pad, h_pad : float
680677
width and height padding (in fraction of figure)
681678
hspace, wspace : float

lib/matplotlib/_tight_layout.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def get_tight_layout_figure(fig, axes_list, subplotspec_list, renderer,
202202
axes_list : list of Axes
203203
subplotspec_list : list of `.SubplotSpec`
204204
The subplotspecs of each axes.
205-
renderer : renderer
205+
renderer : `~matplotlib.backend_bases.RendererBase` subclass
206206
pad : float
207207
Padding between the figure edge and the edges of subplots, as a
208208
fraction of the font size.

lib/matplotlib/artist.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ def get_tightbbox(self, renderer=None):
353353
354354
Parameters
355355
----------
356-
renderer : `.RendererBase` subclass
356+
renderer : `~matplotlib.backend_bases.RendererBase` subclass, optional
357357
renderer that will be used to draw the figures (i.e.
358358
``fig.canvas.get_renderer()``)
359359
@@ -440,7 +440,7 @@ def set_transform(self, t):
440440
441441
Parameters
442442
----------
443-
t : `.Transform`
443+
t : `~matplotlib.transforms.Transform`
444444
"""
445445
self._transform = t
446446
self._transformSet = True
@@ -733,7 +733,7 @@ def set_figure(self, fig):
733733
734734
Parameters
735735
----------
736-
fig : `.Figure`
736+
fig : `~matplotlib.figure.Figure`
737737
"""
738738
# if this is a no-op just return
739739
if self.figure is fig:
@@ -757,16 +757,17 @@ def set_clip_box(self, clipbox):
757757
758758
Parameters
759759
----------
760-
clipbox : `.Bbox`
760+
clipbox : `~matplotlib.transforms.Bbox`
761761
762-
Typically would be created from a `.TransformedBbox`. For
762+
Will typically be created from a `.TransformedBbox`. For
763763
instance ``TransformedBbox(Bbox([[0, 0], [1, 1]]), ax.transAxes)``
764764
is the default clipping for an artist added to an Axes.
765765
766766
"""
767-
self.clipbox = clipbox
768-
self.pchanged()
769-
self.stale = True
767+
if clipbox != self.clipbox:
768+
self.clipbox = clipbox
769+
self.pchanged()
770+
self.stale = True
770771

771772
def set_clip_path(self, path, transform=None):
772773
"""
@@ -987,7 +988,7 @@ def draw(self, renderer):
987988
988989
Parameters
989990
----------
990-
renderer : `.RendererBase` subclass.
991+
renderer : `~matplotlib.backend_bases.RendererBase` subclass.
991992
992993
Notes
993994
-----
@@ -1011,9 +1012,10 @@ def set_alpha(self, alpha):
10111012
f'alpha must be numeric or None, not {type(alpha)}')
10121013
if alpha is not None and not (0 <= alpha <= 1):
10131014
raise ValueError(f'alpha ({alpha}) is outside 0-1 range')
1014-
self._alpha = alpha
1015-
self.pchanged()
1016-
self.stale = True
1015+
if alpha != self._alpha:
1016+
self._alpha = alpha
1017+
self.pchanged()
1018+
self.stale = True
10171019

10181020
def _set_alpha_for_array(self, alpha):
10191021
"""
@@ -1046,9 +1048,10 @@ def set_visible(self, b):
10461048
----------
10471049
b : bool
10481050
"""
1049-
self._visible = b
1050-
self.pchanged()
1051-
self.stale = True
1051+
if b != self._visible:
1052+
self._visible = b
1053+
self.pchanged()
1054+
self.stale = True
10521055

10531056
def set_animated(self, b):
10541057
"""
@@ -1096,9 +1099,11 @@ def set_label(self, s):
10961099
s : object
10971100
*s* will be converted to a string by calling `str`.
10981101
"""
1099-
self._label = str(s) if s is not None else None
1100-
self.pchanged()
1101-
self.stale = True
1102+
label = str(s) if s is not None else None
1103+
if label != self._label:
1104+
self._label = label
1105+
self.pchanged()
1106+
self.stale = True
11021107

11031108
def get_zorder(self):
11041109
"""Return the artist's zorder."""
@@ -1115,9 +1120,10 @@ def set_zorder(self, level):
11151120
"""
11161121
if level is None:
11171122
level = self.__class__.zorder
1118-
self.zorder = level
1119-
self.pchanged()
1120-
self.stale = True
1123+
if level != self.zorder:
1124+
self.zorder = level
1125+
self.pchanged()
1126+
self.stale = True
11211127

11221128
@property
11231129
def sticky_edges(self):

lib/matplotlib/axes/_axes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ class Axes(_AxesBase):
6868
6969
Attributes
7070
----------
71-
dataLim : `.Bbox`
71+
dataLim : `~matplotlib.transforms.Bbox`
7272
The bounding box enclosing all data displayed in the Axes.
73-
viewLim : `.Bbox`
73+
viewLim : `~matplotlib.transforms.Bbox`
7474
The view limits in data coordinates.
7575
7676
"""
@@ -337,7 +337,7 @@ def inset_axes(self, bounds, *, transform=None, zorder=5, **kwargs):
337337
bounds : [x0, y0, width, height]
338338
Lower-left corner of inset Axes, and its width and height.
339339
340-
transform : `.Transform`
340+
transform : `~matplotlib.transforms.Transform`
341341
Defaults to `ax.transAxes`, i.e. the units of *rect* are in
342342
Axes-relative coordinates.
343343
@@ -422,7 +422,7 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
422422
drawn connecting the indicator box to the inset Axes on corners
423423
chosen so as to not overlap with the indicator box.
424424
425-
transform : `.Transform`
425+
transform : `~matplotlib.transforms.Transform`
426426
Transform for the rectangle coordinates. Defaults to
427427
`ax.transAxes`, i.e. the units of *rect* are in Axes-relative
428428
coordinates.
@@ -447,7 +447,7 @@ def indicate_inset(self, bounds, inset_ax=None, *, transform=None,
447447
448448
Returns
449449
-------
450-
rectangle_patch : `.patches.Rectangle`
450+
rectangle_patch : `~matplotlib.patches.Rectangle`
451451
The indicator frame.
452452
453453
connector_lines : 4-tuple of `.patches.ConnectionPatch`
@@ -533,7 +533,7 @@ def indicate_inset_zoom(self, inset_ax, **kwargs):
533533
534534
Returns
535535
-------
536-
rectangle_patch : `.patches.Rectangle`
536+
rectangle_patch : `~matplotlib.patches.Rectangle`
537537
Rectangle artist.
538538
539539
connector_lines : 4-tuple of `.patches.ConnectionPatch`

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4319,7 +4319,7 @@ def get_tightbbox(self, renderer=None, call_axes_locator=True,
43194319
43204320
Parameters
43214321
----------
4322-
renderer : `.RendererBase` subclass
4322+
renderer : `~matplotlib.backend_bases.RendererBase` subclass, optional
43234323
renderer that will be used to draw the figures (i.e.
43244324
``fig.canvas.get_renderer()``)
43254325

lib/matplotlib/backend_bases.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ class DrawEvent(Event):
12991299
13001300
Attributes
13011301
----------
1302-
renderer : `RendererBase`
1302+
renderer : `~matplotlib.backend_bases.RendererBase` subclass
13031303
The renderer for the draw event.
13041304
"""
13051305
def __init__(self, name, canvas, renderer):

lib/matplotlib/backend_managers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class ToolManager:
3636
3737
Attributes
3838
----------
39-
figure : `.Figure`
39+
figure : `~matplotlib.figure.Figure`
4040
keypresslock : `~matplotlib.widgets.LockDraw`
4141
`.LockDraw` object to know if the `canvas` key_press_event is locked.
4242
messagelock : `~matplotlib.widgets.LockDraw`
@@ -81,7 +81,7 @@ def set_figure(self, figure, update_tools=True):
8181
8282
Parameters
8383
----------
84-
figure : `.Figure`
84+
figure : `~matplotlib.figure.Figure`
8585
update_tools : bool, default: True
8686
Force tools to update figure.
8787
"""

lib/matplotlib/backends/backend_pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2733,7 +2733,7 @@ def savefig(self, figure=None, **kwargs):
27332733
27342734
Parameters
27352735
----------
2736-
figure : `.Figure` or int, default: the active figure
2736+
figure : `~matplotlib.figure.Figure` or int, default: the active figure
27372737
The figure, or index of the figure, that is saved to the file.
27382738
"""
27392739
if not isinstance(figure, Figure):

lib/matplotlib/backends/backend_pgf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ def savefig(self, figure=None, **kwargs):
969969
970970
Parameters
971971
----------
972-
figure : `.Figure` or int, default: the active figure
972+
figure : `~matplotlib.figure.Figure` or int, default: the active figure
973973
The figure, or index of the figure, that is saved to the file.
974974
"""
975975
if not isinstance(figure, Figure):

lib/matplotlib/collections.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ def __init__(self, *,
126126
A vector by which to translate each patch after rendering (default
127127
is no translation). The translation is performed in screen (pixel)
128128
coordinates (i.e. after the Artist's transform is applied).
129-
offset_transform : `~.Transform`, default: `.IdentityTransform`
129+
offset_transform : `~matplotlib.transforms.Transform`, default: \
130+
`.IdentityTransform`
130131
A single transform which will be applied to each *offsets* vector
131132
before it is used.
132133
cmap, norm
@@ -228,7 +229,7 @@ def set_offset_transform(self, offset_transform):
228229
229230
Parameters
230231
----------
231-
offset_transform : `.Transform`
232+
offset_transform : `~matplotlib.transforms.Transform`
232233
"""
233234
self._offset_transform = offset_transform
234235

lib/matplotlib/contour.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,8 @@ def add_label_near(self, x, y, inline=True, inline_spacing=5,
568568
Space in pixels to leave on each side of label when placing
569569
inline. This spacing will be exact for labels at locations where
570570
the contour is straight, less so for labels on curved contours.
571-
transform : `.Transform` or `False`, default: ``self.axes.transData``
571+
transform : `~matplotlib.transforms.Transform` or `False`, default: \
572+
``self.axes.transData``
572573
A transform applied to ``(x, y)`` before labeling. The default
573574
causes ``(x, y)`` to be interpreted as data coordinates. `False`
574575
is a synonym for `.IdentityTransform`; i.e. ``(x, y)`` should be

lib/matplotlib/figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,7 @@ def get_tightbbox(self, renderer=None, bbox_extra_artists=None):
17321732
17331733
Parameters
17341734
----------
1735-
renderer : `.RendererBase` subclass
1735+
renderer : `~matplotlib.backend_bases.RendererBase` subclass, optional
17361736
Renderer that will be used to draw the figures (i.e.
17371737
``fig.canvas.get_renderer()``)
17381738
@@ -2167,7 +2167,7 @@ def __init__(self, parent, subplotspec, *,
21672167
"""
21682168
Parameters
21692169
----------
2170-
parent : `.Figure` or `.SubFigure`
2170+
parent : `~matplotlib.figure.Figure` or `.SubFigure`
21712171
Figure or subfigure that contains the SubFigure. SubFigures
21722172
can be nested.
21732173
@@ -2480,7 +2480,7 @@ def __init__(self,
24802480
24812481
Other Parameters
24822482
----------------
2483-
**kwargs : `.Figure` properties, optional
2483+
**kwargs : `~matplotlib.figure.Figure` properties, optional
24842484
24852485
%(Figure:kwdoc)s
24862486
"""

lib/matplotlib/gridspec.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def __init__(self, nrows, ncols, figure=None,
335335
nrows, ncols : int
336336
The number of rows and columns of the grid.
337337
338-
figure : `.Figure`, optional
338+
figure : `~matplotlib.figure.Figure`, optional
339339
Only used for constrained layout to create a proper layoutgrid.
340340
341341
left, right, top, bottom : float, optional
@@ -448,9 +448,9 @@ def tight_layout(self, figure, renderer=None,
448448
449449
Parameters
450450
----------
451-
figure : `.Figure`
451+
figure : `~matplotlib.figure.Figure`
452452
The figure.
453-
renderer : `.RendererBase` subclass, optional
453+
renderer : `~matplotlib.backend_bases.RendererBase` subclass, optional
454454
The renderer to be used.
455455
pad : float
456456
Padding between the figure edge and the edges of subplots, as a

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def composite_images(images, renderer, magnification=1.0):
6767
enforced by this function. Each image must have a purely
6868
affine transformation with no shear.
6969
70-
renderer : `.RendererBase`
70+
renderer : `~matplotlib.backend_bases.RendererBase` subclass
7171
7272
magnification : float, default: 1
7373
The additional magnification to apply for the renderer in use.

lib/matplotlib/layout_engine.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def execute(self, fig):
170170
171171
Parameters
172172
----------
173-
fig : `.Figure` to perform layout on.
173+
fig : `~matplotlib.figure.Figure` to perform layout on.
174174
175175
See Also
176176
--------
@@ -263,7 +263,7 @@ def execute(self, fig):
263263
264264
Parameters
265265
----------
266-
fig : `.Figure` to perform layout on.
266+
fig : `~matplotlib.figure.Figure` to perform layout on.
267267
"""
268268
width, height = fig.get_size_inches()
269269
# pads are relative to the current state of the figure...

lib/matplotlib/legend.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
9696

9797

9898
_legend_kw_doc_base = """
99-
bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats
99+
bbox_to_anchor : `~matplotlib.transforms.BboxBase`, 2-tuple, or 4-tuple of floats
100100
Box that is used to position the legend in conjunction with *loc*.
101101
Defaults to `axes.bbox` (if called as a method to `.Axes.legend`) or
102102
`figure.bbox` (if `.Figure.legend`). This argument allows arbitrary

lib/matplotlib/offsetbox.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ def get_offset(self, bbox, renderer):
305305
306306
Parameters
307307
----------
308-
bbox : `.Bbox`
309-
renderer : `.RendererBase` subclass
308+
bbox : `~matplotlib.transforms.Bbox`
309+
renderer : `~matplotlib.backend_bases.RendererBase` subclass
310310
"""
311311
return (
312312
self._offset(bbox.width, bbox.height, -bbox.x0, -bbox.y0, renderer)
@@ -351,7 +351,7 @@ def _get_bbox_and_child_offsets(self, renderer):
351351
352352
Parameters
353353
----------
354-
renderer : `.RendererBase` subclass
354+
renderer : `~matplotlib.backend_bases.RendererBase` subclass
355355
356356
Returns
357357
-------
@@ -954,7 +954,8 @@ def __init__(self, loc, *,
954954
:rc:`legend.fontsize` is used.
955955
frameon : bool
956956
Whether to draw a frame around the box.
957-
bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats
957+
bbox_to_anchor : `~matplotlib.transforms.BboxBase`, 2-tuple, or 4-tuple of \
958+
floats
958959
Box that is used to position the legend in conjunction with *loc*.
959960
bbox_transform : None or :class:`matplotlib.transforms.Transform`
960961
The transform for the bounding box (*bbox_to_anchor*).

0 commit comments

Comments
 (0)