DataFrame.plot(): changing position of legend with secondary_y removes legend entries
See original GitHub issueCode Sample
df = pd.DataFrame([[1, 1], [2, 4], [3, 7]], index=[1, 2, 3],
columns=['col a', 'col b'])
df.plot(kind='bar', secondary_y=['col b']).legend(bbox_to_anchor=(1.5, 1))
Problem description
The code above produces a barplot with secondary y axis for ‘col b’. The last command (.legend(…)) tells it to move the legend around, which works but produces a new legend that only includes ‘col a’.
Expected Output
I believe it should include both columns in the legend, like it does when the .legend part is omitted. I have also tried to move the legend around with other methods, but with no success.
Output of pd.show_versions()
pandas: 0.19.2 nose: 1.3.7 pip: 8.1.2 setuptools: 35.0.2 Cython: 0.24.1 numpy: 1.12.1 scipy: 0.18.1 statsmodels: 0.6.1 xarray: None IPython: 6.0.0 sphinx: 1.4.6 patsy: 0.4.1 dateutil: 2.6.0 pytz: 2017.2 blosc: None bottleneck: 1.1.0 tables: 3.2.2 numexpr: 2.6.1 matplotlib: 1.5.3 openpyxl: 2.3.2 xlrd: 1.0.0 xlwt: 1.1.2 xlsxwriter: 0.9.3 lxml: 3.6.4 bs4: 4.5.1 html5lib: None httplib2: None apiclient: None sqlalchemy: 1.0.13 pymysql: 0.7.9.None psycopg2: None jinja2: 2.8 boto: 2.42.0 pandas_datareader: None
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:5 (2 by maintainers)
Top GitHub Comments
Hm… it seems to keep the labels this way, although the legend locations differ a bit.
Here’s with
Increasing it to more than 0.7 puts it out of the frame, although that is what I originally intended since I can still view it in IPython Notebook.
Edit: Here’s the original, with
it seems only the column in the secondary axis is left out