-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: Add grouped_bar() method #28560
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
Merged
+517
−12
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fea06c9
ENH: Add grouped_bar() method
timhoffm 556895d
Add tests for grouped_bar()
timhoffm 900ace5
Simplify "Grouped bar chart with labels" using grouped_bar()
timhoffm 7fa82d7
Apply suggestions from code review
timhoffm 8cf06c4
Docstring wording
timhoffm a4ed768
Update lib/matplotlib/axes/_axes.py
timhoffm d9aa5f6
Add test for grouped_bar() return value
timhoffm e0afe74
Apply suggestions from code review
timhoffm 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,15 @@ | ||
import matplotlib.pyplot as plt | ||
|
||
categories = ['A', 'B'] | ||
data0 = [1.0, 3.0] | ||
data1 = [1.4, 3.4] | ||
data2 = [1.8, 3.8] | ||
|
||
fig, ax = plt.subplots(figsize=(4, 2.2)) | ||
ax.grouped_bar( | ||
[data0, data1, data2], | ||
tick_labels=categories, | ||
labels=['dataset 0', 'dataset 1', 'dataset 2'], | ||
colors=['#1f77b4', '#58a1cf', '#abd0e6'], | ||
) | ||
ax.legend() |
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 |
---|---|---|
|
@@ -67,6 +67,7 @@ Basic | |
Axes.bar | ||
Axes.barh | ||
Axes.bar_label | ||
Axes.grouped_bar | ||
|
||
Axes.stem | ||
Axes.eventplot | ||
|
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 |
---|---|---|
|
@@ -60,6 +60,7 @@ Basic | |
bar | ||
barh | ||
bar_label | ||
grouped_bar | ||
stem | ||
eventplot | ||
pie | ||
|
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,26 @@ | ||
Grouped bar charts | ||
------------------ | ||
|
||
The new method `~.Axes.grouped_bar()` simplifies the creation of grouped bar charts | ||
significantly. It supports different input data types (lists of datasets, dicts of | ||
datasets, data in 2D arrays, pandas DataFrames), and allows for easy customization | ||
of placement via controllable distances between bars and between bar groups. | ||
|
||
Example: | ||
|
||
.. plot:: | ||
:include-source: true | ||
:alt: Diagram of a grouped bar chart of 3 datasets with 2 categories. | ||
|
||
timhoffm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import matplotlib.pyplot as plt | ||
|
||
categories = ['A', 'B'] | ||
datasets = { | ||
'dataset 0': [1, 11], | ||
'dataset 1': [3, 13], | ||
'dataset 2': [5, 15], | ||
} | ||
|
||
fig, ax = plt.subplots() | ||
ax.grouped_bar(datasets, tick_labels=categories) | ||
ax.legend() |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.