You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am integrating Matplotlib with the QtBackend inside a tool of data analysis.
I would be interested if the function save_figure from the NavigationToolbar2QT class could return the fullpath of the saved image (the variable fname).
For now I have overloaded this function by adding the return parameter but it would much neater if it was made directly inside matplotlib. Plus, this could interest other people.
For consistency, maybe it would be best to do that for all backends.
What do you think ?
Proposed solution
The function would look like this :
defsave_figure(self, *args):
filetypes=self.canvas.get_supported_filetypes_grouped()
sorted_filetypes=sorted(filetypes.items())
default_filetype=self.canvas.get_default_filetype()
startpath=os.path.expanduser(mpl.rcParams['savefig.directory'])
start=os.path.join(startpath, self.canvas.get_default_filename())
filters= []
selectedFilter=Noneforname, extsinsorted_filetypes:
exts_list=" ".join(['*.%s'%extforextinexts])
filter=f'{name} ({exts_list})'ifdefault_filetypeinexts:
selectedFilter=filterfilters.append(filter)
filters=';;'.join(filters)
fname, filter=QtWidgets.QFileDialog.getSaveFileName(
self.canvas.parent(), "Choose a filename to save to", start,
filters, selectedFilter)
iffname:
# Save dir for next time, unless empty str (i.e., use cwd).ifstartpath!="":
mpl.rcParams['savefig.directory'] =os.path.dirname(fname)
try:
self.canvas.figure.savefig(fname)
exceptExceptionase:
QtWidgets.QMessageBox.critical(
self, "Error saving file", str(e),
QtWidgets.QMessageBox.StandardButton.Ok,
QtWidgets.QMessageBox.StandardButton.NoButton)
returnfname
The text was updated successfully, but these errors were encountered:
Problem
Hello,
I am integrating Matplotlib with the QtBackend inside a tool of data analysis.
I would be interested if the function save_figure from the NavigationToolbar2QT class could return the fullpath of the saved image (the variable fname).
For now I have overloaded this function by adding the return parameter but it would much neater if it was made directly inside matplotlib. Plus, this could interest other people.
For consistency, maybe it would be best to do that for all backends.
What do you think ?
Proposed solution
The function would look like this :
The text was updated successfully, but these errors were encountered: