Repository navigation
Apply requested bar style to legend entry of empty bar plots - #31974
yohaidajurno wants to merge 2 commits into
Conversation
When `bar()` is called with empty data, no Rectangle patches are created, so the BarContainer has no child artist for the legend handler to copy style from. The legend entry therefore fell back to the default style and the first color of the cycle, instead of the color/alpha/etc. that were requested -- inconsistent with how plot() and scatter() handle empty data. Stash a non-drawn sample Rectangle carrying the resolved style on the container and let update_from_first_child fall back to it when there are no children, so the legend entry reflects the requested bar style. Closes matplotlib#21506 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
We do not accept AI generated PRs. Please see https://matplotlib.org/devdocs/devel/contribute.html#use-of-generative-ai Also, there is already an open PR #31973 for this issue and we generally give priority to whichever is opened first. |
PR summary
Closes #21506.
When
bar()is called with empty data, noRectanglepatches are created, so theBarContainerhas no child artist for the legend handler to copy style from. The legend entry therefore fell back to the default style and the first color of the cycle, instead of the requested color/alpha — inconsistent with howplot()andscatter()handle empty data.Fix
Stash a non-drawn sample
Rectanglecarrying the resolved style on the container, and letupdate_from_first_childfall back to it when the container has no children.PR checklist
test_empty_bar_chart_legend_handle_style)test_legend.py+ bar tests pass locally;ruffcleandoc/api/next_api_changes/behavior/🤖 Generated with Claude Code