-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Sharey keyword for boxplot #20968
Changes from 15 commits
cb80356
8d822b0
eb71a8e
dc7f3f5
9cb994c
849105a
64aac34
8dc0e9b
6bff510
cfc0a5f
6c0c324
e0a5515
6b4d371
c1d5cab
26ef598
42d7286
7a65d8a
fd76955
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
||
|
@@ -2567,6 +2567,14 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a versionadded tag (0.23.1) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like this? I added this to v.0.23.1.txt.
If not, could you be more specific about what I should add where, please? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. |
||
|
||
.. versionadded:: 0.23.1 | ||
sharey : bool, default True | ||
Whether y-axes will be shared among subplots | ||
|
||
.. versionadded:: 0.23.1 | ||
`**kwds` : Keyword Arguments | ||
All other plotting keyword arguments to be passed to | ||
matplotlib's boxplot function | ||
|
@@ -2598,7 +2606,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) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -367,6 +367,57 @@ 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 | ||
|
||
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]) | ||
|
||
# behavior without keyword | ||
axes = df.groupby('c').boxplot() | ||
expected = [True, False, True, False] | ||
self._assert_ytickslabels_visibility(axes, expected) | ||
|
||
# set sharey=True should be identical | ||
axes = df.groupby('c').boxplot(sharey=True) | ||
expected = [True, False, True, False] | ||
self._assert_ytickslabels_visibility(axes, expected) | ||
|
||
# sharey=False, all yticklabels should be visible | ||
axes = df.groupby('c').boxplot(sharey=False) | ||
expected = [True, True, True, True] | ||
self._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 | ||
|
||
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]) | ||
|
||
# behavior without keyword | ||
axes = df.groupby('c').boxplot() | ||
expected = [True, True, True, True] | ||
self._assert_xtickslabels_visibility(axes, expected) | ||
|
||
# set sharex=False should be identical | ||
axes = df.groupby('c').boxplot(sharex=False) | ||
expected = [True, True, True, True] | ||
self._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] | ||
self._assert_xtickslabels_visibility(axes, expected) | ||
|
||
@pytest.mark.slow | ||
def test_subplots_timeseries(self): | ||
idx = date_range(start='2014-07-01', freq='M', periods=10) | ||
|
@@ -2921,6 +2972,14 @@ def test_secondary_axis_font_size(self, method): | |
self._check_ticks_props(axes=ax.right_ax, | ||
ylabelsize=fontsize) | ||
|
||
def _assert_ytickslabels_visibility(self, axes, expected): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you you move these to the very top of the class (I think we hvae other checker functions there) |
||
for ax, exp in zip(axes, expected): | ||
self._check_visible(ax.get_yticklabels(), visible=exp) | ||
|
||
def _assert_xtickslabels_visibility(self, axes, expected): | ||
for ax, exp in zip(axes, expected): | ||
self._check_visible(ax.get_xticklabels(), visible=exp) | ||
|
||
|
||
def _generate_4_axes_via_gridspec(): | ||
import matplotlib.pyplot as plt | ||
|
There was a problem hiding this comment.
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