-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
BUG: legend behaves inconsistently when plotting to the same axes #6678
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
Conversation
@TomAugspurger can you take a look at this? |
@sinhrks - you're going to need to rebase this before we can merge it. |
ok, rebased. |
@@ -1345,7 +1379,16 @@ def __init__(self, data, x, y, **kwargs): | |||
def _make_plot(self): | |||
x, y, data = self.x, self.y, self.data | |||
ax = self.axes[0] | |||
ax.scatter(data[x].values, data[y].values, **self.kwds) | |||
|
|||
if self.legend and hasattr(self, 'label') and not self.label is None: |
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 think the and not self.label is None
is redundant. If self.label
is set to None
then label
becomes None
, which is the same as your else
. So this could be
if self.legend and hasattr(self, 'label'):
label = self.label
else:
label = None
unless I'm missing something.
This will technically cause the test suite fail if someone runs the slow tests on py2.6 since the |
Other than that, this should be fine. @sinhrks I'll get to your area plot PR soon. |
hmmm....could enable slow ops on 2.6 (as it skips other things)....let me see |
OK. @sinhrks do you mind changing the asserts in @sinhrks I didn't realize it was already broken before your PR . Could you change the one at the bottom of |
hmm..current plotting DOES seem ok on 2.6 see here: https://travis-ci.org/jreback/pandas/jobs/22479235 (this with matplotlib 1.3.1). am thinking about putting this in master - ownly drawback as this now takes a fair amount of time more than the other runs (master is about 50% faster than these anyhow because of caching). worth it? |
I'm not sure if it's worth it for this specific issue. The actual code is valid python 2.6+, it's just the tests that rely on 2.7+ methods. But if you have other reasons for running the slow ones on 2.6 then go for it. |
@TomAugspurger no...going to pass on the 2.6 slow for now...doesn't seem worth it.... go ahead on this PR when you are ready |
Sure, I've modified condition formula and remove Also, followings are changed:
|
@@ -370,10 +370,12 @@ Bug Fixes | |||
- Bug in ``DataFrame.replace()`` where changing a dtype through replacement | |||
would only replace the first occurrence of a value (:issue:`6689`) | |||
- Better error message when passing a frequency of 'MS' in ``Period`` construction (GH5332) | |||
<<<<<<< HEAD |
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 can be removed when you rebase.
@sinhrks reviewing this today. Sorry it took so long. Would you mind rebasing on top of master? (last time, I promise) I'll get this one merged, then you can rebase your Area one on top of this and we can merge that too. Could you also clean up the docs now that the legend API is so much better?
You can pass I think you can remove the since The rest should be good. You could add a reversed example too if you want, |
@TomAugspurger Sure. Modified docs and rebased. I agree that reversed example in the doc is not necessary. |
BUG: legend behaves inconsistently when plotting to the same axes
Thanks! Ahh I may have been a bit quick on merging. I'll keep my eye on what Travis says https://travis-ci.org/pydata/pandas/builds/23507773 |
Travis is all green: https://travis-ci.org/pydata/pandas/builds/23507773 |
There seems to be some inconsistencies related to
DataFrame.plot
andSeries.plot
legend behaviors.Problems:
DataFrame.plot
orSeries.plot
plots data on the same axes repeatedly:legend
kw and existing legend will be drawn as line artist regardless of actual artist type. Also, legend cannot bereverse
ed if the axes already has a legend.reverse
to all artists including the existing one.subplots
is enabled, line plot draws legends on each axes but bar plot doesn't.label
keyword is passed.Fix:
I've prepared a fix based on following concept, except
hexbin
which doesn't use legend.legend
value.legend=True
and df2 withlegend=False
, only df1's legend should appear.legend='reverse'
d, only df2's legend should be reversed.subplots=True
andlegend=True
, each subplot axes should have its own legend (standardize current line plot behavior).Example Code
Output using current repository
a, b, c, z, y x
. Because df2 was plot bylegend=False
, and df3 was plot bylegend='reverse'
.0, 2
is expected because df2 was plot bylegend=False
.Output after fix

If there is anything should be considered, please let me know. Thanks.