-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: fix sharey overwrite on area plots #37943
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
BUG: fix sharey overwrite on area plots #37943
Conversation
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 add a test which replicates the original behavior and resolves with the patch.
Hey @jreback, I was looking into that but could not locate any area plots tests, could you suggest a suitable location such a test? is it worth starting a similar file like https://github.com/pandas-dev/pandas/blob/master/pandas/tests/plotting/test_hist_method.py for area_method? if so perhaps that should be bigger task at testing the area plots in general? |
could put the tests to |
@charlesdong1991 thanks for the pointers, should have looked closer there indeed 😅 |
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.
lgtm @charlesdong1991
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.
Thanks for the PR!
I just have one minor comment on whatsnew, plus a general question: what if users explicitly specify sharey=False
in df.plot
? Will sharey
previously defined by matplotlib be overridden by pandas (I know such a setting is very silly)?
something like below using example from your test:
df = DataFrame(np.random.rand(4, 2), columns=["x", "y"])
fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
df.plot(ax=ax1, kind="area", sharey=False)
df.plot(ax=ax2, kind="area", sharey=False)
that's a fair question, to me that doesn't make much sense, I see the use of sharey in the plot only when it's pandas to make multiple plots, if you specify an ax then it's a bit weird option in my interpretation. that said, the line plots for instance are not overwriting the behaviour, it's specific to area plots where in the end it sets the min or max limit to 0, and in the process resets the other extreme too. that's all to say that if you pass a specific False, then pandas should maybe overwrite the default with False (to be tested how the line plots handle that actually). |
to be honest I don't know why this snippet if self.ylim is None:
if (data >= 0).all().all():
ax.set_ylim(0, None)
elif (data <= 0).all().all():
ax.set_ylim(None, 0) would be needed at all. if it's area chart, it does use line plots for 0 and the other extreme and the fill between, so it should be already set as min or max limit at 0. but maybe I don't have a good understanding of the system |
As I said, I also don't think this makes much sense, and totally agree with you on the assessment since
unfortunately, I am not very familiar with this snippet either, cannot answer you right now, need a look. but if you could find a way of cleaning this up, feel free to come up with a new PR to do so! |
very nice @lrusnac and any clean-up PR is very welcome! |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff