-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Wrong legend when combining multiple plots on the same axes #39522
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
Same issue here. |
if you try:
The legend shows the text in the right order but the colours have been permuted backwards by one:
If you remove If you have 2 methods with |
I assume the culprit is somewhere around this section of code, but I don't understand how the kwargs are shifted across calls to Unless there is something funky with how the matplotlib wrapper applies keyword arguments on shared plots (in which case, maybe this function is messed up? 🤷). Also note that removing ax = plt.gca()
# Only blue and yellow are switched now; red and green are fine
df.plot('x', 'a', ax=ax, label='one red', color='r')
df.plot('x', 'b', ax=ax, label='two green', color='g')
df.plot('b', 'a', ax=ax, label='three blue', color='b')
df.plot('b', 'a', yerr=0.1, ax=ax, label='four yellow', color='y') |
Thanks @david-zwicker for the report - indeed, I can confirm this reproduces on master, will look into it |
Just tried this out with matplotlib directly, and it displays fine, so the bug is probably to do with pandas this is related to #40044 |
Update: since #40777 , the colours in the legend are now correct. However, due to an open issue in matplotlib, marker info is not yet preserved in the legend, so let's keep this open until then |
The code
results in the following image on my platform:

Note that the labels in the legend are swapped!
I obviously expected the legend to show the correct labels.
The text was updated successfully, but these errors were encountered: