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

Skip to content

Commit a9cb8ce

Browse files
committed
Implement savefig.directory for gtk3 gui
1 parent 4372f76 commit a9cb8ce

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,7 @@ def get_filechooser(self):
537537
fc = FileChooserDialog(
538538
title='Save the figure',
539539
parent=self.win,
540+
path=os.path.expanduser(rcParams.get('savefig.directory', '')),
540541
filetypes=self.canvas.get_supported_filetypes(),
541542
default_filetype=self.canvas.get_default_filetype())
542543
fc.set_current_name(self.canvas.get_default_filename())
@@ -545,6 +546,13 @@ def get_filechooser(self):
545546
def save_figure(self, *args):
546547
fname, format = self.get_filechooser().get_filename_from_user()
547548
if fname:
549+
startpath = os.path.expanduser(rcParams.get('savefig.directory', ''))
550+
if startpath == '':
551+
# explicitly missing key or empty str signals to use cwd
552+
rcParams['savefig.directory'] = startpath
553+
else:
554+
# save dir for next time
555+
rcParams['savefig.directory'] = os.path.dirname(str(fname))
548556
try:
549557
self.canvas.print_figure(fname, format=format)
550558
except Exception, e:

0 commit comments

Comments
 (0)