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

Skip to content

Commit 4372f76

Browse files
committed
Implement savefig.directory for gtk gui
1 parent 4a4ebd1 commit 4372f76

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

lib/matplotlib/backends/backend_gtk.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ def get_filechooser(self):
732732
fc = FileChooserDialog(
733733
title='Save the figure',
734734
parent=self.win,
735+
path=os.path.expanduser(rcParams.get('savefig.directory', '')),
735736
filetypes=self.canvas.get_supported_filetypes(),
736737
default_filetype=self.canvas.get_default_filetype())
737738
fc.set_current_name(self.canvas.get_default_filename())
@@ -740,6 +741,13 @@ def get_filechooser(self):
740741
def save_figure(self, *args):
741742
fname, format = self.get_filechooser().get_filename_from_user()
742743
if fname:
744+
startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
745+
if startpath == '':
746+
# explicitly missing key or empty str signals to use cwd
747+
rcParams['savefig.directory'] = startpath
748+
else:
749+
# save dir for next time
750+
rcParams['savefig.directory'] = os.path.dirname(str(fname))
743751
try:
744752
self.canvas.print_figure(fname, format=format)
745753
except Exception as e:

0 commit comments

Comments
 (0)