BUG: Wrong legend when combining multiple plots on the same axes · Issue #39522 · pandas-dev/pandas (original) (raw)

The code

import matplotlib.pyplot as plt import pandas as pd

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

ax = plt.gca() df.plot('x', 'a', yerr=0.1, ax=ax, label='with errors') df.plot('x', 'b', ax=ax, label='without errors')

results in the following image on my platform:
download
Note that the labels in the legend are swapped!
I obviously expected the legend to show the correct labels.

INSTALLED VERSIONS

commit : 9d598a5e1eee26df95b3910e3f2934890d062caa python : 3.8.7.final.0 python-bits : 64 OS : Darwin OS-release : 19.6.0 Version : Darwin Kernel Version 19.6.0: Tue Nov 10 00:10:30 PST 2020; root:xnu-6153.141.10~1/RELEASE_X86_64 machine : x86_64 processor : i386 byteorder : little LC_ALL : None LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.2.1

numpy : 1.19.5

pytz : 2020.5

dateutil : 2.8.1

pip : 21.0

setuptools : 51.3.3

Cython : 0.29.21

pytest : 6.2.2

hypothesis : None

sphinx : 3.4.3

blosc : None

feather : None

xlsxwriter : None

lxml.etree : 4.4.1

html5lib : 1.1

pymysql : None

psycopg2 : None

jinja2 : 2.11.2

IPython : 7.19.0

pandas_datareader: None

bs4 : None

bottleneck : None

fsspec : None

fastparquet : None

gcsfs : None

matplotlib : 3.3.4

numexpr : None

odfpy : None

openpyxl : None

pandas_gbq : None

pyarrow : None

pyxlsb : None

s3fs : None

scipy : 1.6.0

sqlalchemy : None

tables : None

tabulate : 0.8.7

xarray : None

xlrd : None

xlwt : None

numba : 0.52.0