-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
ENH: Add broadcasted hatch to grouped_bar #30683
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
Closed
ilakkmanoharan
wants to merge
19
commits into
matplotlib:main
from
ilakkmanoharan:enh/grouped-bar-hatch-broadcast
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
787375a
grouped_bar supports broadcasted hatch (one hatch per dataset)
ilakkmanoharan c0d13d1
ENH: Add broadcasted hatch support to grouped_bar (final style fixes)
ilakkmanoharan 3ceee0c
MAINT: regenerate pyplot.py after adding hatch to grouped_bar
ilakkmanoharan 38deb93
Stub: include 'hatch' parameter in Axes.grouped_bar to align with run…
ilakkmanoharan 40bac2e
Stub: include 'hatch' parameter in Axes.grouped_bar to align with run…
ilakkmanoharan f9cf38f
Stub: re-add 'hatch' parameter to Axes.grouped_bar for consistency wi…
ilakkmanoharan 0e8b15e
DOC: behavior note for grouped_bar hatch broadcasting (30683-IM)
ilakkmanoharan 2ca419f
Sync pyplot.py via tools/boilerplate.py after grouped_bar hatch change
ilakkmanoharan 91843e4
Docstring: clarify that an empty string disables hatching in Axes.gro…
ilakkmanoharan 1fc2493
Tests: add grouped_bar edge cases (empty hatch, dict+labels, non-equi…
ilakkmanoharan 3bf57a7
Style: revert lefts assignment to compact upstream format
ilakkmanoharan 42a134d
Fix: restore correct bar alignment in grouped_bar (revert accidental …
ilakkmanoharan 7f7779e
Update doc/api/next_api_changes/behavior/30683-IM.rst
ilakkmanoharan dc499a1
ENH: align hatch broadcasting with color handling in Axes.grouped_bar
ilakkmanoharan 4b255c2
CI: refresh branch to clear stale file diff for test_grouped_bar_hatc…
ilakkmanoharan 7a314e4
Update lib/matplotlib/tests/test_axes.py
ilakkmanoharan 47c575b
Enhance grouped_bar: refine hatch handling, type hints, and tests
ilakkmanoharan a935895
Sync pyplot boilerplate after grouped_bar signature change
ilakkmanoharan 5d8f84c
Refactor grouped_bar orientation logic with common_kwargs and remove …
ilakkmanoharan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| grouped_bar hatch patterns | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
|
||
| `.Axes.grouped_bar` now accepts a list of strings describing hatch patterns, | ||
| which are applied sequentially to the datasets, cycling if fewer patterns are | ||
| provided—similar to how colors are handled. | ||
|
|
||
| .. plot:: | ||
|
|
||
| import matplotlib.pyplot as plt | ||
| import numpy as np | ||
|
|
||
| fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4)) | ||
|
|
||
| x = np.arange(3) | ||
| heights = [ | ||
| [1, 2, 3], | ||
| [2, 1, 2], | ||
| [3, 2, 1], | ||
| ] | ||
|
|
||
| ax1.grouped_bar(heights, tick_labels=["A", "B", "C"], hatch="/") | ||
| ax2.grouped_bar(heights, tick_labels=["A", "B", "C"], hatch=["/", "\\\\", ".."]) | ||
|
|
||
| ax1.set_title("hatch='/'") | ||
| ax2.set_title("hatch=['/', '\\\\', '..']") | ||
|
|
||
| plt.show() | ||
|
|
||
| The first plot applies the same hatch to all bars. | ||
| The second plot uses a different hatch for each dataset, cycling automatically | ||
| if the list of hatches is shorter than the number of datasets. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we have enforced the length of the list then I think we do not need
itertools.cycle. But why do we enforce the length for hatches when we didn’t for colors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are good arguments for and against enforcing length. Since we currently do not do this in most parts of the library, let's stick to that approach for now. Enforcing length is a separate discussion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @rcomer and @timhoffm, for the helpful comments and feedback! I’ll review them and make the necessary updates.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rcomer @timhoffm
If you confirm that we can allow cycling for this PR, I’ll go ahead and make the required changes.
I’ve also opened an issue to discuss this behavior more broadly and reach a consensus, since it could be a useful improvement across style arguments:
[MNT]: DISCUSSION: Should Axes.grouped_bar() enforce hatch list length or allow cycling like colors? (#30712)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ilakkmanoharan for this PR, please allow cycling and do not enforce the list length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rcomer @timhoffm Okay, I will allow cycling and not enforce the list length for this PR