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

Skip to content

Commit a226171

Browse files
authored
Merge pull request #9090 from NelleV/savefig_improve_error_mesg
[MAINT] savefig only takes one args
2 parents 86bca7a + aee94c9 commit a226171

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/matplotlib/figure.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,7 @@ def add_axobserver(self, func):
17091709
'whenever the axes state change, ``func(self)`` will be called'
17101710
self._axobservers.append(func)
17111711

1712-
def savefig(self, *args, **kwargs):
1712+
def savefig(self, fname, **kwargs):
17131713
"""
17141714
Save the current figure.
17151715
@@ -1787,7 +1787,6 @@ def savefig(self, *args, **kwargs):
17871787
tight bbox is calculated.
17881788
17891789
"""
1790-
17911790
kwargs.setdefault('dpi', rcParams['savefig.dpi'])
17921791
frameon = kwargs.pop('frameon', rcParams['savefig.frameon'])
17931792
transparent = kwargs.pop('transparent',
@@ -1811,7 +1810,7 @@ def savefig(self, *args, **kwargs):
18111810
original_frameon = self.get_frameon()
18121811
self.set_frameon(frameon)
18131812

1814-
self.canvas.print_figure(*args, **kwargs)
1813+
self.canvas.print_figure(fname, **kwargs)
18151814

18161815
if frameon:
18171816
self.set_frameon(original_frameon)

lib/matplotlib/tests/test_figure.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,3 +319,10 @@ def test_subplots_shareax_loglabels():
319319

320320
for ax in ax_arr[:, 0]:
321321
assert 0 < len(ax.yaxis.get_ticklabels(which='both'))
322+
323+
324+
def test_savefig():
325+
fig, ax = plt.subplots()
326+
msg = "savefig() takes 2 positional arguments but 3 were given"
327+
with pytest.raises(TypeError, message=msg):
328+
fig.savefig("fname1.png", "fname2.png")

0 commit comments

Comments
 (0)