Skip to content
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: plotting with secondary_y and then plotting another line results in wrong color for (right) line #40044

Closed
3 tasks done
MarcoGorelli opened this issue Feb 25, 2021 · 2 comments · Fixed by #40777
Closed
3 tasks done
Labels
Milestone

Comments

@MarcoGorelli
Copy link
Member

MarcoGorelli commented Feb 25, 2021

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • (optional) I have confirmed this bug exists on the master branch of pandas.


Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Code Sample, a copy-pastable example

import pandas as pd

df = pd.DataFrame({'a': [1, 1], 'b': [2, 2]})
df2 = pd.DataFrame({'d': [2.5, 2.5]})

ax = df.plot(legend=True, secondary_y='b')
df2.plot(legend=False, ax=ax);

Problem description

Here's what we get:

image

Expected Output

The colours in the legend should be correct, i.e.:

image

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 2724350
python : 3.8.6.final.0
python-bits : 64
OS : Linux
OS-release : 5.4.0-66-generic
Version : #74-Ubuntu SMP Wed Jan 27 22:54:38 UTC 2021
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_GB.UTF-8
LOCALE : en_GB.UTF-8

pandas : 1.3.0.dev0+841.g272435073c
numpy : 1.19.5
pytz : 2021.1
dateutil : 2.8.1
pip : 20.3.3
setuptools : 49.6.0.post20201009
Cython : 0.29.21
pytest : 6.2.2
hypothesis : 6.2.0
sphinx : 3.5.1
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.3
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 0.8.5
fastparquet : 0.5.0
gcsfs : 0.7.2
matplotlib : 3.3.3
numexpr : 2.7.2
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 2.0.0
pyxlsb : None
s3fs : 0.5.2
scipy : 1.6.0
sqlalchemy : 1.3.23
tables : 3.6.1
tabulate : 0.8.7
xarray : 0.16.2
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.52.0

@MarcoGorelli MarcoGorelli added Bug Visualization plotting Needs Triage Issue that has not been reviewed by a pandas team member labels Feb 25, 2021
@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Feb 25, 2021

The correct behaviour can be obtained by reverting #27808 - however, then we'd lose marker info

As far as I can tell, there isn't a way to do something like leg.legendHandles and retain marker info, I'm looking into possible workarounds

cc @charlesdong1991

@MarcoGorelli
Copy link
Member Author

MarcoGorelli commented Feb 26, 2021

This doesn't just happen with legend=False, but anytime another plot is made:

import pandas as pd

df = pd.DataFrame({'a': [1, 1], 'b': [2, 3]})
df2 = pd.DataFrame({'d': [2.5, 2.5]})

ax = df.plot(legend=True, color={'a': 'blue', 'b': 'green'}, secondary_y='b')
df2.plot(legend=True, color={'d': 'red'}, ax=ax);

image


Expected output:

image

@MarcoGorelli MarcoGorelli changed the title BUG: plotting with legend=False messes up legend BUG: plotting with secondary_y and then plotting another line results in wrong color for (right) line Feb 26, 2021
@lithomas1 lithomas1 removed the Needs Triage Issue that has not been reviewed by a pandas team member label Feb 27, 2021
@MarcoGorelli MarcoGorelli mentioned this issue Apr 4, 2021
5 tasks
@jreback jreback added this to the 1.3 milestone Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants