Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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.20.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ Plotting

- Bug in ``DataFrame.plot`` with a single column and a list-like ``color`` (:issue:`3486`)
- Bug in ``plot`` where ``NaT`` in ``DatetimeIndex`` results in ``Timestamp.min`` (:issue: `12405`)
- Bug in ``DataFrame.boxplot`` where ``figsize`` keyword was not respected for non-grouped boxplots (:issue:`11959`)



Expand Down
14 changes: 5 additions & 9 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,10 @@ def _get_standard_kind(kind):
return {'density': 'kde'}.get(kind, kind)


def _gca():
def _gca(rc=None):
import matplotlib.pyplot as plt
return plt.gca()
with plt.rc_context(rc):
return plt.gca()


def _gcf():
Expand Down Expand Up @@ -1871,12 +1872,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 +2001,8 @@ def plot_group(keys, values, ax):
"'by' is None")

if ax is None:
ax = _gca()
rc = {'figure.figsize': figsize} if figsize is not None else {}
ax = _gca(rc)
data = data._get_numeric_data()
if columns is None:
columns = data.columns
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/plotting/test_boxplot_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ def test_boxplot_empty_column(self):
df.loc[:, 0] = np.nan
_check_plot_works(df.boxplot, return_type='axes')

@slow
def test_figsize(self):
df = DataFrame(np.random.rand(10, 5), columns=['A', 'B', 'C', 'D', 'E'])
Copy link
Contributor

Choose a reason for hiding this comment

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

this line might be a bit longn too. flake8 pandas/tests/plotting/test_boxplot_method.py should tell you.

result = df.boxplot(return_type='axes', figsize=(12,8))
Copy link
Contributor

Choose a reason for hiding this comment

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

You'll need a comma between the 12 and 8, otherwise our style cheker will complain.

assert result.figure.bbox_inches.width == 12
assert result.figure.bbox_inches.height == 8

def test_fontsize(self):
df = DataFrame({"a": [1, 2, 3, 4, 5, 6]})
self._check_ticks_props(df.boxplot("a", fontsize=16),
Expand Down