8000 [MAINT] savefig only takes one args by NelleV · Pull Request #9090 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[MAINT] savefig only takes one args #9090

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[MAINT] savefig only takes one args
Making this explicit improves error message when user provides
two args to the function.
  • Loading branch information
NelleV committed Aug 24, 2017
commit aee94c916b1ec279f9de8d019d1ed996bbb3adf7
5 changes: 2 additions & 3 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ def add_axobserver(self, func):
'whenever the axes state change, ``func(self)`` will be called'
self._axobservers.append(func)

def savefig(self, *args, **kwargs):
def savefig(self, fname, **kwargs):
"""
Save the current figure.

Expand Down Expand Up @@ -1787,7 +1787,6 @@ def savefig(self, *args, **kwargs):
tight bbox is calculated.

"""

kwargs.setdefault('dpi', rcParams['savefig.dpi'])
frameon = kwargs.pop('frameon', rcParams['savefig.frameon'])
transparent = kwargs.pop('transparent',
Expand All @@ -1811,7 +1810,7 @@ def savefig(self, *args, **kwargs):
original_frameon = self.get_frameon()
self.set_frameon(frameon)

self.canvas.print_figure(*args, **kwargs)
self.canvas.print_figure(fname, **kwargs)

if frameon:
self.set_frameon(original_frameon)
Expand Down
7 changes: 7 additions & 0 deletions lib/matplotlib/tests/test_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,3 +319,10 @@ def test_subplots_shareax_loglabels():

for ax in ax_arr[:, 0]:
assert 0 < len(ax.yaxis.get_ticklabels(which='both'))


def test_savefig():
fig, ax = plt.subplots()
msg = "savefig() takes 2 positional arguments but 3 were given"
with pytest.raises(TypeError, message=msg):
fig.savefig("fname1.png", "fname2.png")
0