Skip to content

Commit 36b3761

Browse files
committed
add default savefig directory
1 parent 2188187 commit 36b3761

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

lib/matplotlib/backends/backend_qt4.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,9 @@ def save_figure(self, *args):
644644
sorted_filetypes.sort()
645645
default_filetype = self.canvas.get_default_filetype()
646646

647-
start = self.canvas.get_default_filename()
647+
startpath = matplotlib.rcParams.get('savefig.directory', os.getcwd())
648+
startpath = os.path.expanduser(startpath)
649+
start = os.path.join(startpath, self.canvas.get_default_filename())
648650
filters = []
649651
selectedFilter = None
650652
for name, exts in sorted_filetypes:
@@ -657,6 +659,7 @@ def save_figure(self, *args):
657659
fname = _getSaveFileName(self, "Choose a filename to save to",
658660
start, filters, selectedFilter)
659661
if fname:
662+
matplotlib.rcParams['savefig.directory'] = os.path.split(str(fname))[0]
660663
try:
661664
self.canvas.print_figure( unicode(fname) )
662665
except Exception as e:

lib/matplotlib/rcsetup.py

+1
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ def __call__(self, s):
686686
# options are 'tight', or 'standard'. 'standard' validates to None.
687687
'savefig.bbox': [None, validate_bbox],
688688
'savefig.pad_inches': [0.1, validate_float],
689+
'savefig.directory': ['', str],
689690

690691
# Maintain shell focus for TkAgg
691692
'tk.window_focus': [False, validate_bool],

matplotlibrc.template

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ text.hinting_factor : 8 # Specifies the amount of softness for hinting in the
366366
#savefig.format : png # png, ps, pdf, svg
367367
#savefig.bbox : standard # 'tight' or 'standard'.
368368
#savefig.pad_inches : 0.1 # Padding to be used when bbox is set to 'tight'
369+
#savefig.directory : ~ # default directory in savefig dialog box
369370

370371
# tk backend params
371372
#tk.window_focus : False # Maintain shell focus for TkAgg

0 commit comments

Comments
 (0)