Skip to content

VIS: Allow xlabel and ylabel in DataFrame.plot.scatter plot and hexbin plot #37001

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

Closed
3 tasks done
treuherz opened this issue Oct 9, 2020 · 4 comments · Fixed by #37102
Closed
3 tasks done

VIS: Allow xlabel and ylabel in DataFrame.plot.scatter plot and hexbin plot #37001

treuherz opened this issue Oct 9, 2020 · 4 comments · Fixed by #37102
Assignees
Milestone

Comments

@treuherz
Copy link
Contributor

treuherz commented Oct 9, 2020

  • 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.


Code Sample

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib as mpl

ax = (pd.DataFrame(np.random.randn(100, 2), columns=['A','B'])
    .plot.scatter(
        x='A',
        y='B',
        xlabel='my x label',
        ylabel='my y label',
    )
)

Problem description

In #34223 (released in 1.1.0), the ability to set xlabel and ylabel in DataFrame.plot() was added. This works fine when calling plot() directly or df.plot.line(). When calling df.plot.scatter() with these args, you still get the index labels as the axis labels, instead of the strings you pass in.

These args are not documented to be incompatible or unavailable on this function, and no error is printed.

Actual Output

Expected Output

The plot's axis labels should be the strings provided, "my x label" and "my y label".

Output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit           : db08276bc116c438d3fdee492026f8223584c477
python           : 3.8.5.final.0
python-bits      : 64
OS               : Darwin
OS-release       : 19.6.0
Version          : Darwin Kernel Version 19.6.0: Sun Jul  5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_GB.UTF-8
LOCALE           : en_GB.UTF-8

pandas           : 1.1.3
numpy            : 1.19.2
pytz             : 2020.1
dateutil         : 2.8.1
pip              : 20.2.3
setuptools       : 50.3.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 2.11.2
IPython          : 7.18.1
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : 3.3.2
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pytables         : None
pyxlsb           : None
s3fs             : None
scipy            : 1.5.2
sqlalchemy       : None
tables           : None
tabulate         : 0.8.7
xarray           : None
xlrd             : None
xlwt             : None
numba            : None
@treuherz treuherz added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 9, 2020
@charlesdong1991
Copy link
Member

charlesdong1991 commented Oct 9, 2020

thanks @treuherz for the report

Indeed, scatter plot doesn't support xlabel and ylabel like other plots (e.g. line, bar etc) due to slightly different implementations under the hood

so it is not a bug, just not implemented yet. i think it's quite easy to implement those two features, do you want to give it a try for a PR?

@charlesdong1991 charlesdong1991 added Enhancement Visualization plotting and removed Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 9, 2020
@charlesdong1991 charlesdong1991 added this to the Contributions Welcome milestone Oct 9, 2020
@charlesdong1991 charlesdong1991 changed the title BUG: xlabel and ylabel have no effect on DataFrame.plot.scatter() VIS: Allow xlabel and ylabel in DataFrame.plot.scatter plot and hexbin plot Oct 9, 2020
@treuherz
Copy link
Contributor Author

treuherz commented Oct 9, 2020

Sure, I had some time over lunch to dig and I think I've found the offending function in PlanePlot:

def _post_plot_logic(self, ax: "Axes", data):
x, y = self.x, self.y
ax.set_ylabel(pprint_thing(y))
ax.set_xlabel(pprint_thing(x))

Happy to take a stab at a PR, give me a couple of days.

@charlesdong1991
Copy link
Member

you are very welcome! and just take your time for the PR! @treuherz

you could also assign it to yourself so that everyone knows you are working on it :)

@treuherz
Copy link
Contributor Author

take

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants