Skip to content

Sharey keyword for boxplot #20968

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 18 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
8 changes: 8 additions & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,14 @@ yourself. To revert to the old setting, you can run this line:

pd.options.display.max_columns = 20

.. _whatsnew_0230.boxplot.sharexy:

Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot()
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't an API change, so we don't need this long of a release note. Probably a single line saying that boxplot now accepts the sharey keyword, and a link to a more detailed example in the docstring or plotting.rst

Copy link
Author

Choose a reason for hiding this comment

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

I updated the docstring and the the part in v0.23.0.txt.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this to 0.23.1.txt now?

Copy link
Contributor

Choose a reason for hiding this comment

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

And I think the example can be trimmed down. I'd rather update the docstring for DataFrame.plot.box since that's a longer-term thing. The release note are for people checking changes. They'll see that it now supports sharey, and click through if interested.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(:issue:`15184`)
Copy link
Contributor

Choose a reason for hiding this comment

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

this file needs to be reverted


Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot()

.. _whatsnew_0230.api.datetimelike:

Datetimelike API Changes
Expand Down
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.23.1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ I/O
Plotting
^^^^^^^^

-
- Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() (:issue: `20968`)
Copy link
Contributor

Choose a reason for hiding this comment

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

its not clear to me what is being fixed / enhancement here, can you re-word

-

Reshaping
Expand Down
8 changes: 6 additions & 2 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2548,7 +2548,7 @@ def plot_group(group, ax):

def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None,
rot=0, grid=True, ax=None, figsize=None,
layout=None, **kwds):
layout=None, sharex=False, sharey=True, **kwds):
"""
Make box plots from DataFrameGroupBy data.

Expand All @@ -2567,6 +2567,10 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None,
figsize : A tuple (width, height) in inches
layout : tuple (optional)
(rows, columns) for the layout of the plot
sharex : bool, default False
Whether x-axes will be shared among subplots
Copy link
Contributor

@jreback jreback May 29, 2018

Choose a reason for hiding this comment

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

add a versionadded tag (0.23.1)

Copy link
Author

@sorenwacker sorenwacker May 29, 2018

Choose a reason for hiding this comment

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

Like this? I added this to v.0.23.1.txt.

Plotting
^^^^^^^^

- Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() (:issue: `20968`)

If not, could you be more specific about what I should add where, please?

Copy link
Contributor

@TomAugspurger TomAugspurger May 29, 2018

Choose a reason for hiding this comment

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

    sharey : bool, default False
        Whether y-axes will be shared among subplots 

        .. versionadded:: 0.23.1

Copy link
Author

Choose a reason for hiding this comment

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

Thank you.

sharey : bool, default True
Whether y-axes will be shared among subplots
`**kwds` : Keyword Arguments
All other plotting keyword arguments to be passed to
matplotlib's boxplot function
Expand Down Expand Up @@ -2598,7 +2602,7 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None,
if subplots is True:
naxes = len(grouped)
fig, axes = _subplots(naxes=naxes, squeeze=False,
ax=ax, sharex=False, sharey=True,
ax=ax, sharex=sharex, sharey=sharey,
figsize=figsize, layout=layout)
axes = _flatten(axes)

Expand Down
59 changes: 59 additions & 0 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,65 @@ def test_subplots(self):
for ax in axes:
assert ax.get_legend() is None

def test_groupby_boxplot_sharey(self):
# https://github.com/pandas-dev/pandas/issues/20968
# sharey can now be switched check whether the right
# pair of axes is turned on or off

def _assert_ytickslabels_visibility(axes, expected):
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have similar functions at a top level? maybe we should

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I am new to pandas. I am not sure whether I understand what you mean. Are you saying, I should move the function somewhere else? If yes, where exactly should the function go?

Copy link
Contributor

Choose a reason for hiding this comment

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

you can make this a function on the class itself rather than defininig it inside the function

for ax, exp in zip(axes, expected):
self._check_visible(ax.get_yticklabels(), visible=exp)

df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14],
'b': [0.56, 0.84, 0.29, 0.56, 0.85],
'c': [0, 1, 2, 3, 1]},
index=[0, 1, 2, 3, 4])

# standart behavior
Copy link
Contributor

Choose a reason for hiding this comment

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

standard

Copy link
Contributor

Choose a reason for hiding this comment

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

what is 'standard' mean here, can you update the comment

Copy link
Author

Choose a reason for hiding this comment

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

Done.

axes = df.groupby('c').boxplot()
expected = [True, False, True, False]
_assert_ytickslabels_visibility(axes, expected)
Copy link
Contributor

Choose a reason for hiding this comment

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

use a blank line between cases


# set sharey=True should be identical
axes = df.groupby('c').boxplot(sharey=True)
expected = [True, False, True, False]
_assert_ytickslabels_visibility(axes, expected)

# sharey=False, all yticklabels should be visible
axes = df.groupby('c').boxplot(sharey=False)
expected = [True, True, True, True]
_assert_ytickslabels_visibility(axes, expected)

def test_groupby_boxplot_sharex(self):
# https://github.com/pandas-dev/pandas/issues/20968
# sharex can now be switched check whether the right
# pair of axes is turned on or off

def _assert_xtickslabels_visibility(axes, expected):
for ax, exp in zip(axes, expected):
self._check_visible(ax.get_xticklabels(), visible=exp)

df = DataFrame({'a': [-1.43, -0.15, -3.70, -1.43, -0.14],
'b': [0.56, 0.84, 0.29, 0.56, 0.85],
'c': [0, 1, 2, 3, 1]},
index=[0, 1, 2, 3, 4])

# standart behavior
axes = df.groupby('c').boxplot()
expected = [True, True, True, True]
_assert_xtickslabels_visibility(axes, expected)

# set sharex=False should be identical
axes = df.groupby('c').boxplot(sharex=False)
expected = [True, True, True, True]
_assert_xtickslabels_visibility(axes, expected)

# sharex=True, yticklabels should be visible
# only for bottom plots
axes = df.groupby('c').boxplot(sharex=True)
expected = [False, False, True, True]
_assert_xtickslabels_visibility(axes, expected)

@pytest.mark.slow
def test_subplots_timeseries(self):
idx = date_range(start='2014-07-01', freq='M', periods=10)
Expand Down