Skip to content

Commit c18bbad

Browse files
committed
explicitly missing key or empty str signals to use cwd
1 parent 4c8b930 commit c18bbad

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

lib/matplotlib/backends/backend_qt4.py

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

647-
startpath = matplotlib.rcParams.get('savefig.directory', os.getcwd())
647+
startpath = matplotlib.rcParams.get('savefig.directory', '')
648648
startpath = os.path.expanduser(startpath)
649649
start = os.path.join(startpath, self.canvas.get_default_filename())
650650
filters = []
@@ -659,7 +659,12 @@ def save_figure(self, *args):
659659
fname = _getSaveFileName(self, "Choose a filename to save to",
660660
start, filters, selectedFilter)
661661
if fname:
662-
matplotlib.rcParams['savefig.directory'] = os.path.split(str(fname))[0]
662+
if startpath == '':
663+
# explicitly missing key or empty str signals to use cwd
664+
matplotlib.rcParams['savefig.directory'] = startpath
665+
else:
666+
# save dir for next time
667+
matplotlib.rcParams['savefig.directory'] = os.path.dirname(str(fname))
663668
try:
664669
self.canvas.print_figure( unicode(fname) )
665670
except Exception as e:

lib/matplotlib/rcsetup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,8 @@ 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],
689+
# default directory in savefig dialog box
690+
'savefig.directory': ['~', str],
690691

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

matplotlibrc.template

+2-1
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ 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
369+
#savefig.directory : ~ # default directory in savefig dialog box,
370+
# leave empty to always use current working directory
370371

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

0 commit comments

Comments
 (0)