Skip to content

Don't ignore figsize in df.boxplot #16445

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 6 commits into from
May 24, 2017
Merged
Changes from 1 commit
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
23 changes: 13 additions & 10 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,18 @@ def _get_standard_kind(kind):
return {'density': 'kde'}.get(kind, kind)


def _gca():
def _gca(figsize=None):
Copy link
Contributor

@TomAugspurger TomAugspurger May 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change _gca to take an optional dictionary? So like

def _gca(rc=None):
    with plt.rc_context(rc):
        return plt.gca()

that way, we aren't limited to just figsize when we call gca. You'd call it like ax = _gca({'figure.figsize': figsize})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that. Note that I can't unconditionally overwrite figure.figsize, because if it's not specified, it's None, and that would overwrite the default in rcParams. That's why I have it pass in an empty dict when it's None. Anyway, I can push that one level up the call stack like you mention.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah that's unfortunate. Still probably best to handle it outside.

import matplotlib.pyplot as plt
return plt.gca()
if figsize is not None:
# No way of passing in figsize via gca() call so temporarily change the
# defaults so that when it calls figure() it uses our figsize.
old_figsize = plt.rcParams.get('figure.figsize')
plt.rcParams['figure.figsize'] = figsize
try:
return plt.gca()
finally:
if figsize is not None:
plt.rcParams['figure.figsize'] = old_figsize


def _gcf():
Expand Down Expand Up @@ -1871,14 +1880,8 @@ def plot_series(data, kind='line', ax=None, # Series unique
**kwds):

import matplotlib.pyplot as plt
"""
If no axes is specified, check whether there are existing figures
If there is no existing figures, _gca() will
create a figure with the default figsize, causing the figsize=parameter to
be ignored.
"""
if ax is None and len(plt.get_fignums()) > 0:
ax = _gca()
ax = _gca(figsize)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would maybe revert this change, since we pass figsize through to _plot, presumably it's handled there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed that, thanks. Changing it back.

ax = MPLPlot._get_ax_layer(ax)
return _plot(data, kind=kind, ax=ax,
figsize=figsize, use_index=use_index, title=title,
Expand Down Expand Up @@ -2006,7 +2009,7 @@ def plot_group(keys, values, ax):
"'by' is None")

if ax is None:
ax = _gca()
ax = _gca(figsize)
data = data._get_numeric_data()
if columns is None:
columns = data.columns
Expand Down