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

Skip to content

FIX: subplots don't mutate kwargs passed by user. #11601

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 2 commits into from
Jul 9, 2018
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
3 changes: 3 additions & 0 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1471,6 +1471,9 @@ def subplots(self, nrows=1, ncols=1, sharex=False, sharey=False,
subplot_kw = {}
if gridspec_kw is None:
gridspec_kw = {}
# don't mutate kwargs passed by user...
subplot_kw = subplot_kw.copy()
gridspec_kw = gridspec_kw.copy()

if self.get_constrained_layout():
gs = GridSpec(nrows, ncols, figure=self, **gridspec_kw)
Expand Down
9 changes: 9 additions & 0 deletions lib/matplotlib/tests/test_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,12 @@ def test_get_gridspec():
# ahem, pretty trivial, but...
fig, ax = plt.subplots()
assert ax.get_subplotspec().get_gridspec() == ax.get_gridspec()


def test_dont_mutate_kwargs():
subplot_kw = {'sharex': 'all'}
gridspec_kw = {'width_ratios': [1, 2]}
fig, ax = plt.subplots(1, 2, subplot_kw=subplot_kw,
gridspec_kw=gridspec_kw)
assert subplot_kw == {'sharex': 'all'}
assert gridspec_kw == {'width_ratios': [1, 2]}