-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
pandas.DataFrame.plot(): Labels do not appear in legend #9542
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
Comments
Is anyone working on this? I could take a stab if not. |
@schmohlio Certainly try! I think there are two issues that could be fixed:
|
@jorisvandenbossche thanks for the notes! I think some of the confusion also stems from the purpose of the How do we want to handle multiple series? Should the label default to the index if multiple series are called, or continue to represent the last label assignment? Should we automatically generate a legend for multiple series filled with label kwargs vals? Or, should we perhaps start by removing the legend altogether? Thanks! |
Just circling back to your notes, though, it makes sense that the legend handlers should not yield "None", and that the labels should pass through to the labels. I'll be taking a deeper look. |
@schmohlio IIRC, I think we have handling in there for what to do when a second Series is plotted on an axes that already contains a Series.plot (with or without a legend). I can't look now, but I think my last tweak to this code was fixing a bug where the label wouldn't show up if it was |
Some more observations (and these can then be turned into tests):
And above things then should also work when adding multiple series to the same ax (as the original example) |
Thanks @jorisvandenbossche. Looks like the addtl kwargs were running through a loop with One last question. For your last bulleted test, what should the x axis of the graph be labeled with? should it be the index ( |
Nvm. Will maintain behavior of |
I modified some tests within the pandas.tests.test_graphics module where series tests did not match dataframe plot tests. I have a working commit (passed all your tests when exploring in a notebook). Also, 5 tests have errors on master, and thus they continue to fail on my branch. Just submitted a pull request. I think the changes are straightforward. Thanks, |
New behavior:
This code produces a chart with two series where the legend is properly labeled ( Series indices are no longer mutated and labels are default to column names if |
Closed by #9574 |
@schmohlio @TomAugspurger I think I have identified this issue causing a regression in legend plotting. Today I upgraded pandas via conda to 0.16.1, and the behaviour of my plotting code changed! Up until now I have been setting labels, without problems, like this (based on @schmohlio 's example above, reduced from the real code as much as possible):
Expected behaviour: Until now, this plotted the legend entries "mylabel_1" and "mylabel2", respectively. Question 1: Was this an intended change or an unintended regression of this bug? |
@bilderbuchi Sorry about that. It was a regression. It's fixed by #10131 so your options are to
|
Thank you. I searched the tracker, but only for open issues >.<. |
awesome response time, btw! |
Yes, we’ll possibly have a 0.16.2 release. Otherwise 0.17 will contain the fix.
|
I tested @bilderbuchi 's code and it's fine. But if I select the dataframe column with double quote [[]], it will ignore the assigned label and legend the column name. I think this is not the expected behaviour? df[['sin(x)']].plot(ax=ax_1, label='mylabel_1')
df['cos(x)'].plot(ax=ax_2, label='mylabel_2') |
Selecting with `[[]]`` will return a DataFrame, not a Series. I don't think this added support for multiple labels. |
Have we resolved multiple label issue? I want to add multiple labels for each column of my df. |
Similar to #9542 (comment),
|
I am having exactly the same problem, on January 2021. |
Having the same issue as previously noted. Using
but the output plot has 'Training cost' as the label instead of the specified 'ADAM'. Wondering what the fix is? |
I can reproduce the same behavior as the previous comments. Its probably best if a new issue is opened for this. |
Yes, please open a new issue, as additional comments on an old and closed issue like this one will more likely get ignored or missed. |
The following code plots two lines. The column names appear in the legend.
However, the following equivalent code shows None as legend, even though the labels are explicitly set.
Of course there are alternative ways to make this work, but it appears to me that passing the labels should suffice. In particular, I don't think their values should be replaced with None, or printed as x-label.
The text was updated successfully, but these errors were encountered: