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

Skip to content

Commit 9b3eb2e

Browse files
committed
Return filename from save_figure function
1 parent d2cc4d0 commit 9b3eb2e

File tree

7 files changed

+14
-2
lines changed

7 files changed

+14
-2
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3224,7 +3224,14 @@ def on_tool_fig_close(e):
32243224
return self.subplot_tool
32253225

32263226
def save_figure(self, *args):
3227-
"""Save the current figure."""
3227+
"""
3228+
Save the current figure.
3229+
3230+
Returns
3231+
-------
3232+
str or `None`
3233+
The filepath of the saved figure. For GTK4 and Web backends it returns None.
3234+
"""
32283235
raise NotImplementedError
32293236

32303237
def update(self):

lib/matplotlib/backend_bases.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class NavigationToolbar2:
441441
def push_current(self) -> None: ...
442442
subplot_tool: widgets.SubplotTool
443443
def configure_subplots(self, *args): ...
444-
def save_figure(self, *args) -> None: ...
444+
def save_figure(self, *args) -> str | None: ...
445445
def update(self) -> None: ...
446446
def set_history_buttons(self) -> None: ...
447447

lib/matplotlib/backends/_backend_tk.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@ def save_figure(self, *args):
884884
self.canvas.figure.savefig(fname, format=extension)
885885
except Exception as e:
886886
tkinter.messagebox.showerror("Error saving file", str(e))
887+
return fname
887888

888889
def set_history_buttons(self):
889890
state_map = {True: tk.NORMAL, False: tk.DISABLED}

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ def on_notify_filter(*args):
383383
type=Gtk.MessageType.ERROR, buttons=Gtk.ButtonsType.OK)
384384
dialog.run()
385385
dialog.destroy()
386+
return fname
386387

387388

388389
class ToolbarGTK3(ToolContainerBase, Gtk.Box):

lib/matplotlib/backends/backend_macosx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def save_figure(self, *args):
146146
if mpl.rcParams['savefig.directory']:
147147
mpl.rcParams['savefig.directory'] = os.path.dirname(filename)
148148
self.canvas.figure.savefig(filename)
149+
return filename
149150

150151

151152
class FigureManagerMac(_macosx.FigureManager, FigureManagerBase):

lib/matplotlib/backends/backend_qt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,7 @@ def save_figure(self, *args):
839839
self, "Error saving file", str(e),
840840
QtWidgets.QMessageBox.StandardButton.Ok,
841841
QtWidgets.QMessageBox.StandardButton.NoButton)
842+
return fname
842843

843844
def set_history_buttons(self):
844845
can_backward = self._nav_stack._pos > 0

lib/matplotlib/backends/backend_wx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,7 @@ def save_figure(self, *args):
11201120
caption='Matplotlib error')
11211121
dialog.ShowModal()
11221122
dialog.Destroy()
1123+
return path
11231124

11241125
def draw_rubberband(self, event, x0, y0, x1, y1):
11251126
height = self.canvas.figure.bbox.height

0 commit comments

Comments
 (0)