-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #20968 +/- ##
==========================================
+ Coverage 91.85% 91.88% +0.03%
==========================================
Files 153 153
Lines 49570 49564 -6
==========================================
+ Hits 45533 45543 +10
+ Misses 4037 4021 -16
Continue to review full report at Codecov.
|
We'll want tests for this. See the e.g. |
Thanks. I will look into that and give it a try. |
Hello @soerendip! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on June 08, 2018 at 11:26 Hours UTC |
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -898,6 +898,48 @@ 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() |
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.
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
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.
I updated the docstring and the the part in v0.23.0.txt.
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.
Can you move this to 0.23.1.txt now?
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.
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.
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -898,6 +898,48 @@ 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() |
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.
Can you move this to 0.23.1.txt now?
doc/source/whatsnew/v0.23.0.txt
Outdated
@@ -898,6 +898,48 @@ 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() |
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.
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.
doc/source/whatsnew/v0.23.0.txt
Outdated
|
||
Previous Behavior: | ||
|
||
.. code-block:: jupyter-notebook |
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.
See the other examples in /pandas/plotting/_core.py
for how these should be formatted.
doc/source/whatsnew/v0.23.0.txt
Outdated
|
||
... | ||
|
||
df.groupby('Class').boxplot(sharey=True, sharex=True) |
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.
Won't need all of these. Probably just one will convey the point.
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.
Ok, 0.23.1.txt does not exist yet. When I fetch from upstream I don't receive it. Does that mean I should create that file? I thought I already removed the example. Not sure why it still there.
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.
@soerendip did you merge after fetching? The file is there already on master
Done. Hope it is correct this time. |
pandas/plotting/_core.py
Outdated
@@ -2567,6 +2567,12 @@ 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 : |
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.
Could you take a look at http://pandas.pydata.org/pandas-docs/stable/contributing_docstring.html for how to format these? Something like
sharex : bool, default False
Whether the horizontal axes is shared among subplots
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.
Ok, did that. Should this part of the doc-string then be corrected as well?
subplots :
* ``False`` - no subplots will be used
* ``True`` - create a subplot for each group
pandas/tests/plotting/test_frame.py
Outdated
|
||
# standart behavior | ||
axes = df.groupby('c').boxplot() | ||
self._check_visible(axes[0].get_yticklabels(), visible=True) |
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.
These tests are a bit wordy. I wonder if the following is clear?
expected = pd.Series([True, False, True, False])
result = axes.apply(lambda ax: ax.yaxis.get_visible())
tm.assert_frame_equal(result, expected)
Is that the same? Do you find it clearer?
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.
I see where you want to go. Would this be acceptable? It uses a function that you might want somewhere else though in case you want to use it in other tests? Where would be a good position to put it?
def test_groupby_boxplot_sharex(self):
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, xticklabels should be visible only for bottom plots
axes = df.groupby('c').boxplot(sharex=True)
expected = [False, False, True, True]
_assert_xtickslabels_visibility(axes, expected)´
Any updates on this? I shortened the tests in the style of your examples using the assert function that was implemented to check for visibility. However, I had to create two helper functions, and was not sure where the optimal place for those is. |
@@ -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 |
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.
add a versionadded tag (0.23.1)
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.
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?
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.
sharey : bool, default False
Whether y-axes will be shared among subplots
.. versionadded:: 0.23.1
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.
Thank you.
pandas/tests/plotting/test_frame.py
Outdated
# sharey can now be switched check whether the right | ||
# pair of axes is turned on or off | ||
|
||
def _assert_ytickslabels_visibility(axes, expected): |
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.
do we have similar functions at a top level? maybe we should
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.
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?
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.
you can make this a function on the class itself rather than defininig it inside the function
pandas/tests/plotting/test_frame.py
Outdated
# standart behavior | ||
axes = df.groupby('c').boxplot() | ||
expected = [True, False, True, False] | ||
_assert_ytickslabels_visibility(axes, expected) |
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.
use a blank line between cases
All changes should be done. |
doc/source/whatsnew/v0.23.0.txt
Outdated
|
||
Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
(:issue:`15184`) |
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.
this file needs to be reverted
pandas/tests/plotting/test_frame.py
Outdated
# sharey can now be switched check whether the right | ||
# pair of axes is turned on or off | ||
|
||
def _assert_ytickslabels_visibility(axes, expected): |
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.
you can make this a function on the class itself rather than defininig it inside the function
pandas/tests/plotting/test_frame.py
Outdated
'c': [0, 1, 2, 3, 1]}, | ||
index=[0, 1, 2, 3, 4]) | ||
|
||
# standart behavior |
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.
standard
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.
what is 'standard' mean here, can you update the comment
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.
Done.
…or tests without keywords
@soerendip looks like tests are failing in the latest commit. |
That’s when you think “it’s so easy it can’t fail”... will look into this.
…________________________________
From: Tom Augspurger <[email protected]>
Sent: Wednesday, June 6, 2018 2:31:23 PM
To: pandas-dev/pandas
Cc: Sören; Mention
Subject: Re: [pandas-dev/pandas] Sharey keyword for boxplot (#20968)
@soerendip<https://github.com/soerendip> looks like tests are failing in the latest commit.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#20968 (comment)>, or mute the thread<https://github.com/notifications/unsubscribe-auth/ADPAfiKwkip_0MRFE3KD0qoRShVy2QZ0ks5t6EorgaJpZM4T0HJx>.
|
doc/source/whatsnew/v0.23.1.txt
Outdated
@@ -76,7 +76,7 @@ I/O | |||
Plotting | |||
^^^^^^^^ | |||
|
|||
- | |||
- Optional sharing of x/y-axis by pandas.DataFrame().groupby().boxplot() (:issue: `20968`) |
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
pandas/tests/plotting/test_frame.py
Outdated
@@ -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 comment
The 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)
Done. |
thanks @soerendip |
…to _subplots().
.. code-block:: jupyter-notebook
%pylab inline
import pandas as pd
New Behavior:
.. ipython:: jpyter-notebook:
To restore previous behavior, use boxplot() without keywords.
Default is the previous behavior of sharey
git diff upstream/master -u -- "*.py" | flake8 --diff