-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: xticks in bar plot breaks plot #55508
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
Comments
@gdementen '2.0.3's = pd.Series([1, 3, 2], index=[2010, 2015, 2020]) works fine (see line.png)s.plot(xticks=[2010, 2030]) ticks and bars are all squashed to the right of the plot (see bar.png)s.plot.bar(xticks=[0, 20]) works fine too |
Hi If the range not starts from zero then we do have this issue My range starts from zero |
I write the code in the jupyter qtconsole: import pandas as pd
mydf = pd.DataFrame(data={"col_a": [1, 2, 3], "col_b": [4, 5, 6]}, index=[1900, 1950, 2000])
mydf
"""
col_a col_b
1900 1 4
1950 2 5
2000 3 6
"""
mydf.index
"""
Index([1900, 1950, 2000], dtype='int64')
"""
ax = mydf.col_a.plot(kind="bar") ax = mydf.col_a.plot(kind="bar")
ax.set_xlim([0, 10]) ax.xaxis.get_ticklocs()
"""
array([0, 1, 2])
"""
pd.__version__
"""
'2.1.3'
""" The problem is that the Pandas' For correct plotting I should get ax.xaxis.get_ticklocs()
"""
array([1900, 1950, 2000])
""" That is obviously a bug in my opinion. |
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 main branch of pandas.
Reproducible Example
Issue Description
When using the xticks argument on a bar plot, it is kind of "squashed" to the right of the plot.

Ticks and bars are all on a single tick on the right:
For line plots, this works fine:

The issue is also present in Pandas 2.1.1 (latest stable version as of today) and Pandas 1.5.3. It might be related to #11465.
Expected Behavior
Installed Versions
INSTALLED VERSIONS
commit : 0f43794
python : 3.10.13.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19045
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 12, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : French_Belgium.1252
pandas : 2.0.3
numpy : 1.22.3
pytz : 2023.3.post1
dateutil : 2.8.2
setuptools : 68.0.0
pip : 23.2.1
Cython : 0.29.33
pytest : 7.3.1
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : 3.1.1
lxml.etree : 4.9.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.15.0
pandas_datareader: None
bs4 : 4.12.2
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : 0.57.0
numexpr : 2.8.7
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : 3.8.0
tabulate : None
xarray : None
xlrd : 2.0.1
zstandard : None
tzdata : 2023.3
qtpy : 2.2.0
pyqt5 : None
The text was updated successfully, but these errors were encountered: