Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit16f6370

Browse files
authored
Merge pull request#22813 from greglucas/rm-dpi-changed
MNT: Deprecate figure callbacks
2 parents2c5fc8e +6a1b8c6 commit16f6370

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
``figure.callbacks`` is deprecated
2+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The figure callbacks property is deprecated. The only signal was
4+
"dpi_changed", which can be replaced by connecting to the "resize_event"
5+
on the canvas ``figure.canvas.mpl_connect("resize_event", func)`` instead.

‎lib/matplotlib/figure.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,6 +1976,10 @@ class SubFigure(FigureBase):
19761976
19771977
See :doc:`/gallery/subplots_axes_and_figures/subfigures`
19781978
"""
1979+
callbacks=_api.deprecated(
1980+
"3.6",alternative=("the 'resize_event' signal in "
1981+
"Figure.canvas.callbacks")
1982+
)(property(lambdaself:self._fig_callbacks))
19791983

19801984
def__init__(self,parent,subplotspec,*,
19811985
facecolor=None,
@@ -2024,7 +2028,7 @@ def __init__(self, parent, subplotspec, *,
20242028
self._subplotspec=subplotspec
20252029
self._parent=parent
20262030
self.figure=parent.figure
2027-
self.callbacks=parent.callbacks
2031+
self._fig_callbacks=parent._fig_callbacks
20282032

20292033
# subfigures use the parent axstack
20302034
self._axstack=parent._axstack
@@ -2156,11 +2160,6 @@ class Figure(FigureBase):
21562160
"""
21572161
The top level container for all the plot elements.
21582162
2159-
The Figure instance supports callbacks through a *callbacks* attribute
2160-
which is a `.CallbackRegistry` instance. The events you can connect to
2161-
are 'dpi_changed', and the callback will be called with ``func(fig)`` where
2162-
fig is the `Figure` instance.
2163-
21642163
Attributes
21652164
----------
21662165
patch
@@ -2171,6 +2170,12 @@ class Figure(FigureBase):
21712170
depending on the renderer option_image_nocomposite function. If
21722171
*suppressComposite* is a boolean, this will override the renderer.
21732172
"""
2173+
# Remove the self._fig_callbacks properties on figure and subfigure
2174+
# after the deprecation expires.
2175+
callbacks=_api.deprecated(
2176+
"3.6",alternative=("the 'resize_event' signal in "
2177+
"Figure.canvas.callbacks")
2178+
)(property(lambdaself:self._fig_callbacks))
21742179

21752180
def__str__(self):
21762181
return"Figure(%gx%g)"%tuple(self.bbox.size)
@@ -2303,7 +2308,7 @@ def __init__(self,
23032308
# everything is None, so use default:
23042309
self.set_layout_engine(layout=layout)
23052310

2306-
self.callbacks=cbook.CallbackRegistry(signals=["dpi_changed"])
2311+
self._fig_callbacks=cbook.CallbackRegistry(signals=["dpi_changed"])
23072312
# Callbacks traditionally associated with the canvas (and exposed with
23082313
# a proxy property), but that actually need to be on the figure for
23092314
# pickling.
@@ -2502,7 +2507,7 @@ def _set_dpi(self, dpi, forward=True):
25022507
self.dpi_scale_trans.clear().scale(dpi)
25032508
w,h=self.get_size_inches()
25042509
self.set_size_inches(w,h,forward=forward)
2505-
self.callbacks.process('dpi_changed',self)
2510+
self._fig_callbacks.process('dpi_changed',self)
25062511

25072512
dpi=property(_get_dpi,_set_dpi,doc="The resolution in dots per inch.")
25082513

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp