Fix grouped_bar: legend labels, colors, and hatch handling #30768
+189
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR summary
This pull request fixes issues with the grouped_bar method in Axes related to legend labels, bar colors, and hatch patterns.
Why is this change necessary?
Previously, single labels passed to grouped_bar were not applied to all bars, resulting in empty legends. Additionally, color and hatch patterns were not consistently applied across all grouped bars, and passing label and color twice could cause a TypeError.
What problem does it solve?
Ensures that a single label string propagates to all datasets.
Correctly applies colors and hatch patterns for each bar.
Prevents TypeError when labels or colors are passed multiple times.
Updates tests to verify proper handling of single and multiple labels.
What is the reasoning for this implementation?
By expanding single labels to a list internally and correctly mapping colors and hatches to each dataset, we preserve intuitive usage of grouped_bar and maintain correct legend, color, and hatch behavior without changing the API.
Example usage:
PR checklist
closes [Bug]: grouped_bar can pass label and color twice, causing TypeError #30739