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
Open
timhoffm wants to merge6 commits intomatplotlib:mainChoose a base branch fromtimhoffm:grouped_bar
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
+503 −12
Open
Changes fromall commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
121c21d
ENH: Add grouped_bar() method
timhoffm8963636
Add tests for grouped_bar()
timhoffmbf2894a
Simplify "Grouped bar chart with labels" using grouped_bar()
timhoffmdfcd52f
Apply suggestions from code review
timhoffm6a9dfc8
Docstring wording
timhoffm9e17cad
Update lib/matplotlib/axes/_axes.py
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 |
---|---|---|
@@ -61,6 +61,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.