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

Skip to content

Commit 5bcaa23

Browse files
committed
update documentation of save_figure functions
2 parents b46071c + 174015c commit 5bcaa23

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
``NavigationToolbar2.save_figure`` now returns filepath of saved figure
22
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33

4-
``NavigationToolbar2.save_figure`` function may return the filename of the saved figure.
4+
``NavigationToolbar2.save_figure`` function may return the filename of the saved figure.
55

66
If a backend implements this functionality it should return `None` in the case where no
77
figure is actually saved (because the user closed the dialog without saving).
88

9-
If the backend does not or can not implement this functionality (currently the Gtk4 backends
9+
If the backend does not or can not implement this functionality (currently the Gtk4 backends
1010
and webagg backends do not) this this method will return `NavigationToolbar2.UNKNOWN_SAVED_STATUS`.

lib/matplotlib/backend_bases.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3229,12 +3229,22 @@ def save_figure(self, *args):
32293229
"""
32303230
Save the current figure.
32313231
3232+
Backend implementations may choose to return
3233+
the absolute path of the saved file, if any, as
3234+
a string.
3235+
3236+
If no file is created then `None` is returned.
3237+
3238+
If the backend does not implement this functionality
3239+
then `NavigationToolbar2.UNKNOWN_SAVED_STATUS` is returned.
3240+
32323241
Returns
32333242
-------
3234-
str or `None`
3243+
str or `None` or `NavigationToolbar2.UNKNOWN_SAVED_STATUS`
32353244
The filepath of the saved figure.
3236-
For GTK4 and WebAgg backends it returns `None`.
32373245
Returns `None` if figure is not saved.
3246+
For GTK4 and WebAgg backends it returns
3247+
`NavigationToolbar2.UNKNOWN_SAVED_STATUS`.
32383248
"""
32393249
raise NotImplementedError
32403250

lib/matplotlib/backend_bases.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,7 @@ class _Mode(str, Enum):
406406

407407
class NavigationToolbar2:
408408
toolitems: tuple[tuple[str, ...] | tuple[None, ...], ...]
409+
UNKNONW_SAVED_STATUS: object
409410
canvas: FigureCanvasBase
410411
mode: _Mode
411412
def __init__(self, canvas: FigureCanvasBase) -> None: ...
@@ -441,7 +442,7 @@ class NavigationToolbar2:
441442
def push_current(self) -> None: ...
442443
subplot_tool: widgets.SubplotTool
443444
def configure_subplots(self, *args): ...
444-
def save_figure(self, *args) -> str | None | object: ...
445+
def save_figure(self, *args) -> str | None | UNKNONW_SAVED_STATUS: ...
445446
def update(self) -> None: ...
446447
def set_history_buttons(self) -> None: ...
447448

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ def save_figure(self, *args):
11211121
caption='Matplotlib error')
11221122
dialog.ShowModal()
11231123
dialog.Destroy()
1124-
1124+
11251125
def draw_rubberband(self, event, x0, y0, x1, y1):
11261126
height = self.canvas.figure.bbox.height
11271127
self.canvas._rubberband_rect = (x0, height - y0, x1, height - y1)

0 commit comments

Comments
 (0)