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
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.21.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Other Enhancements
- ``RangeIndex.append`` now returns a ``RangeIndex`` object when possible (:issue:`16212`)
- :func:`to_pickle` has gained a protocol parameter (:issue:`16252`). By default, this parameter is set to `HIGHEST_PROTOCOL <https://docs.python.org/3/library/pickle.html#data-stream-format>`__
- :func:`api.types.infer_dtype` now infers decimals. (:issue: `15690`)
- ``DataFrame.boxplot`` now respects the ``figsize`` keyword for non-grouped boxplots (:issue:`11959`)

.. _whatsnew_0210.api_breaking:

Expand Down
16 changes: 7 additions & 9 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,13 @@ 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()
# No way of passing in figsize via gca() call so temporarily change the
# defaults so that when it calls figure() it uses our figsize.
rc = {'figure.figsize': figsize} if figsize is not None else {}
with plt.rc_context(rc):
return plt.gca()


def _gcf():
Expand Down Expand Up @@ -1871,12 +1875,6 @@ 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 = MPLPlot._get_ax_layer(ax)
Expand Down Expand Up @@ -2006,7 +2004,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