Skip to content

BUG: xlabel/ylabel don't work as expected with barh plots #45144

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
stefmolin opened this issue Dec 31, 2021 · 0 comments · Fixed by #45145
Closed
3 tasks done

BUG: xlabel/ylabel don't work as expected with barh plots #45144

stefmolin opened this issue Dec 31, 2021 · 0 comments · Fixed by #45145
Labels
Milestone

Comments

@stefmolin
Copy link
Contributor

Pandas version checks

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

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

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

Reproducible Example

import pandas as pd

df = pd.DataFrame(
    {'A': [4, 2, 1, 2, 5, 2]}, index=pd.RangeIndex(6, name='B')
)

df.plot(kind='barh', xlabel='x', ylabel='y')

Issue Description

With bar plots, we can pass xlabel and ylabel to plot() and have those values set as the x- and y-axis labels (overriding any defaults). However, if you try this with a barh plot both xlabel and ylabel update the y-axis label, and the only way to update the x-axis label is after the fact with ax.set_xlabel(). Here's the result for the code above:

image

Expected Behavior

With the code provided above, I would expect this:

image

In addition, providing only xlabel should label the x-axis only (currently, this updates the y-axis label, which is confusing).

Installed Versions

INSTALLED VERSIONS

commit : 945c9ed
python : 3.9.6.final.0
python-bits : 64
OS : Darwin
OS-release : 19.6.0
Version : Darwin Kernel Version 19.6.0: Thu Sep 16 20:58:47 PDT 2021; root:xnu-6153.141.40.1~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.3.4
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 52.0.0.post20210125
Cython : 0.29.25
pytest : 6.2.5
hypothesis : 6.29.3
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.2
IPython : 7.29.0
pandas_datareader: 0.10.0
bs4 : None
bottleneck : 1.3.2
fsspec : None
fastparquet : None
gcsfs : None
matplotlib : 3.4.2
numexpr : 2.7.3
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : None

@stefmolin stefmolin added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Dec 31, 2021
@jreback jreback added this to the 1.5 milestone Jan 10, 2022
@jbrockmendel jbrockmendel added the Visualization plotting label Jan 10, 2022
@mroeschke mroeschke removed the Needs Triage Issue that has not been reviewed by a pandas team member label Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants