Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
+517 −12
Merged
Changes fromall commits
Commits
Show all changes
8 commits Select commitHold shift + click to select a range
fea06c9
ENH: Add grouped_bar() method
timhoffm556895d
Add tests for grouped_bar()
timhoffm900ace5
Simplify "Grouped bar chart with labels" using grouped_bar()
timhoffm7fa82d7
Apply suggestions from code review
timhoffm8cf06c4
Docstring wording
timhoffma4ed768
Update lib/matplotlib/axes/_axes.py
timhoffmd9aa5f6
Add test for grouped_bar() return value
timhoffme0afe74
Apply suggestions from code review
timhoffmFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletionsdoc/_embedded_plots/grouped_bar.py
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] | ||
timhoffm marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
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() |
1 change: 1 addition & 0 deletionsdoc/api/axes_api.rst
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 | ||
1 change: 1 addition & 0 deletionsdoc/api/pyplot_summary.rst
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 | ||
26 changes: 26 additions & 0 deletionsdoc/users/next_whats_new/grouped_bar.rst
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 resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
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() |
16 changes: 4 additions & 12 deletionsgalleries/examples/lines_bars_and_markers/barchart.py
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.
Uh oh!
There was an error while loading.Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.