BUG: plotting with secondary_y and then plotting another line results in wrong color for (right) line · Issue #40044 · pandas-dev/pandas (original) (raw)


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