-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: RuntimeError when bar_label of stacked bar chart comes to rest outside of plot's Y limit #25625
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
The layout manager is a red herring as it happens w/o the layout manager too. I suspect #23688 is not behaving if the label is off the page. ping @stefmolin @immaxchen |
The bar labels have a custom coordinate: matplotlib/lib/matplotlib/axes/_axes.py Lines 2769 to 2774 in 8ca75e4
However, Bbox.intersection returns None when there's no overlap, and not some sort of empty Bbox , and so the Annotation locator breaks since it doesn't understand that type:matplotlib/lib/matplotlib/text.py Lines 1453 to 1460 in 8ca75e4
|
Somewhat related to #24104 (comment) |
I am running into this exact same issue, but it seems to be as of the result of a semi recent change. I had a google colab notebook to auto convert a standardized excel output into a labeled bargraph. Bar_label worked as intended without the runtime error as of 1/26/2023. I recently revisited this notebook on 4/6/2023 and it no longer was working due to the issue referenced in the original post. I tested out the notebook on old data that I knew had worked previously and was still facing this error. |
I believe I have a solution thanks to @QuLogic's comments. |
one dirty and temporary solution which worked for me was to apply some margin: |
This was closed by #25681 and will be release in 3.7.2. |
Uh oh!
There was an error while loading. Please reload this page.
Bug summary
When creating a stacked bar chart and annotating its components by use of the
bar_label
method, aRuntimeError("Unknown return type")
exception is raised the moment one of the bar labels comes to rest outside the specified Y limits.Code for reproduction
Actual outcome
Expected outcome
I'd expect the corresponding section of the bar, along with its label, to simply be outside the visible plot area. Or at least a more descriptive error message.
Additional information
The exception seems to happen the moment one of the bar labels cannot fit in the visible plot area anymore. This can be seen by starting with a large Y limit, and slowly lowering it.
As the Y limit approaches the position of the topmost label, it will be shifted down on its own. However the moment the Y limit is set low enough that the topmost bar's component is fully outside the visible area, the exception arises.
The (mostly) minimal reproducible example above contains several Y limits to indicate this happening.
Operating system
Arch Linux, Linux 6.2.5
Matplotlib Version
3.7.1
Matplotlib Backend
TkAgg
Python version
3.10.9
Jupyter version
Not applicable
Installation
pip
The text was updated successfully, but these errors were encountered: