-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: stacked bar graphs show invalid label position due to invalid rectangle bottom when data is 0 #59429
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
take |
Thanks @KevsterAmp for looking into this |
All good, just waiting for this issue to be triaged by a maintainer before working on it. |
@KinzigFlyer - seems like this is a problem on matplotlib not on the pandas itself |
I don't think so, |
Good point, thank you |
Thanks for the report - PRs to fix are welcome! |
I will take this. |
Thank you @KinzigFlyer for the in depth write up. I have made a pull request (#60211) with changes that should fix the bug along with a regression test. Pictured below is the given Reproducible Example when run on the current main branch of pandas: Here is the given Reproducible Example when run on the fix: Here is the regression test case when run on the current main branch of pandas: Here is the regression test case when run on the fix: As you can see, the pull request fixes the bug to match the expected behavior. It should be noted that there is some ambiguity to the expected behavior. Should bar slices of zero height still display labels? This behavior causes labels to overlap which makes them appear bolded as stated before. I do not know the intended behavior here, but am willing to make changes to my pull request to match it if a maintainer suggests one way or the other. My current pull request takes the path of least impact, and display labels even for bar slices of zero height. |
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
if the top part of the stacked plot has data value 0, the bar-label does not appear on top, but at the bottom of the bar.

Further debugging shows that all bars with data = 0 have their y position set to 0.0. They should have the top of the bar below as their bottom = y.
Expected Behavior
Bar-Labels should be positioned on top for all stacks.
this behaviour can be produced by correcting the y positions of the defective bars
Installed Versions
INSTALLED VERSIONS
commit : d9cdd2e
python : 3.11.9.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 186 Stepping 2, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 2.2.2
numpy : 2.0.1
pytz : 2024.1
dateutil : 2.9.0.post0
setuptools : 65.5.0
pip : 24.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.26.0
pandas_datareader : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : 4.12.3
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.9.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.0
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: