René's URL Explorer Experiment


Title: ENH: Add grouped_bar() method by timhoffm · Pull Request #28560 · matplotlib/matplotlib · GitHub

Open Graph Title: ENH: Add grouped_bar() method by timhoffm · Pull Request #28560 · matplotlib/matplotlib

X Title: ENH: Add grouped_bar() method by timhoffm · Pull Request #28560 · matplotlib/matplotlib

Description: This is a WIP to implement #24313. It will be updated incrementally. As a first step, I've designed the data and label input API. Please check the included example, which explains the API variants and motivations/consistency considerations. It's a WIP for the illustration and discussion of the API, and will not go into the final PR I've flagged as "work in progress" because many aspects are not implemented yet. **But please give comments as I consider the implemented parts as complete proposal for that aspects.** The API proposal is complete. Please check whether it is reasonable. You can get an overview the preliminary overview example and in the API docs for grouped_bar. Design decisions and background are listed in right below in the todos: 👉 Ready for review What's new API docs Updated example, which is now much simpler. Todos: API: How to structure and interpret the two data dimensions and the associated labels. For now, only categorical labels are supported as x. Should we also support numbers as with bar? Numbers are now also supported. How to parametrize bar width and group spacing? A bar group takes horizontal space w (default: 1). I believe explicit bar widths are not helpful because they can easily overflow if enough bars are in a group, and "reasonable" values need fine-tuning for per number of bars in a group. I therefore suggest to define the spacing (margin / padding; name t.b.d.) in relative units. Options: padding in units of w: e.g. pad=0.1 would mean a bar group targeting the interval (x-0.5*w, x+0.5*w) would have the outer bar edges at (x-(0.5-pad*w), x+(0.5-pad*w) = (x-0.4w, x+0.4w)`. padding as multiples of the bar width: e.g. a pad=1 would mean that the bar width is chosen so that there's a padding of 1-bar width on both sides of the group. I believe, we can choose reasonable defaults for both cases. It's possibly easier to tune a desired look with the second approach, but harder if one wants to fully control positions. Decision: Implemented as multiples of bar width Do we want to support spacing between the bars in a group? Yes. Spacing should follow the same relative conventions as group padding. Since we have num_bars times the spacing "spacing in units of w will require tuning depending on the number of bars. Spacing would be universal when given as "fraction of bar width". When defaulting to 0 (my slight preference) both variants will work for any number of bars by default. How to support horizontal bars? Use orientation parameter. Replicating to a separate function grouped_barh is overly cumbersome. Do we want to support stacked bars? And grouped stacked bars? - Not for now/here. While stacked bars could use the same input datastructures, other plotting parameters like width and spacing settings do not match, and some bar() flexibility like varying width will not be available via grouped_bar(). I thus recommend not to try and squeeze stacked bars in to grouped_bar(). Stacking bars is already much simpler with the existing bar() methods compared to grouping bars. bar() is thus more sufficient. If we want a higher level interface, a separate stacked_bar() would be a thin wrapper around bar(). I don't see a reasonable function for stacked and grouped bars, because the addtional dimension of data and labelling would make the interface very difficult. If you need stacked and grouped bars, you should use a loop of grouped_bar() with adjusted bottom. support kwargs (Rectangle properties) support vectorized style parameters - at least colors optional: support bottom values, so that one could stack (but could be added later) dataset labels naming? label as in bar(), or labels or dataset_labels or … Note: stackplot() uses labels. This would be an argument for consistency. What's different: We potentially have two labels: dataset labels and group labels. This may warrant deviating from the simple labels apporach to disambiguate them. OTOH, I feel "dataset" is quite a generic name (but I don't have any better) so that it does not make things much clearer. The group labels are implicit in x (or historically in bar(), called tick_labels. I'm going with labels because its consistent with stackplot() and bar() (which uses label) consistent with legend labels always being specified through label a longer name does not significantly help with disambiguation add pyplot wrapper add mypy stubs improve documentation add tests Should we mark this as provisional? This would allow to react to user feedback. -> Yes. What is the return type? List of BarContainer, a new BarGroupContainer, something else, nothing for a start (because we can't decide yet)? Going with list[BarContainer}. This is most simple and in analogy to what stackplot() does. Since the API is provisional, we can still reconsider.

Open Graph Description: This is a WIP to implement #24313. It will be updated incrementally. As a first step, I've designed the data and label input API. Please check the included example, which explains the API varia...

X Description: This is a WIP to implement #24313. It will be updated incrementally. As a first step, I've designed the data and label input API. Please check the included example, which explains the API v...

Opengraph URL: https://github.com/matplotlib/matplotlib/pull/28560

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:abf44aa0-b8cf-4673-a54b-f4e3d790f3da
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA990:120FB6:C31A:10387:6A523370
html-safe-nonce48456ec6f19bb091a1414e7556dccaeca11149ae49356982ff4f57f7cc864697
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTkwOjEyMEZCNjpDMzFBOjEwMzg3OjZBNTIzMzcwIiwidmlzaXRvcl9pZCI6IjE1MjE1MTgwMzA2ODQ4Mjg1MjgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmace3d3c7d961d803f3d1a8cebec671df230e01b004948c4c99ba6dbb56130b17b2
hovercard-subject-tagpull_request:1967742971
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/28560/files
twitter:imagehttps://avatars.githubusercontent.com/u/2836374?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/2836374?s=400&v=4
og:image:altThis is a WIP to implement #24313. It will be updated incrementally. As a first step, I've designed the data and label input API. Please check the included example, which explains the API varia...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Noneb9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git
octolytics-dimension-user_id215947
octolytics-dimension-user_loginmatplotlib
octolytics-dimension-repository_id1385122
octolytics-dimension-repository_nwomatplotlib/matplotlib
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1385122
octolytics-dimension-repository_network_root_nwomatplotlib/matplotlib
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release7aed05249554b889eb33d002851a973eebcc7e91
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/matplotlib/matplotlib/pull/28560/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fpull%2F28560%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmatplotlib%2Fmatplotlib%2Fpull%2F28560%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=matplotlib%2Fmatplotlib
Reloadhttps://github.com/matplotlib/matplotlib/pull/28560/files
Reloadhttps://github.com/matplotlib/matplotlib/pull/28560/files
Reloadhttps://github.com/matplotlib/matplotlib/pull/28560/files
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
matplotlib https://github.com/matplotlib
matplotlibhttps://github.com/matplotlib/matplotlib
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
Notifications https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Fork 8.4k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Star 23k https://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib
Code https://github.com/matplotlib/matplotlib
Issues 1.1k https://github.com/matplotlib/matplotlib/issues
Pull requests 409 https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality 0 https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Code https://github.com/matplotlib/matplotlib
Issues https://github.com/matplotlib/matplotlib/issues
Pull requests https://github.com/matplotlib/matplotlib/pulls
Actions https://github.com/matplotlib/matplotlib/actions
Projects https://github.com/matplotlib/matplotlib/projects
Wiki https://github.com/matplotlib/matplotlib/wiki
Security and quality https://github.com/matplotlib/matplotlib/security
Insights https://github.com/matplotlib/matplotlib/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fmatplotlib%2Fmatplotlib%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fmatplotlib%2Fmatplotlib%2Fissues%2Fnew%2Fchoose
QuLogichttps://github.com/QuLogic
matplotlib:mainhttps://github.com/matplotlib/matplotlib/tree/main
timhoffm:grouped_barhttps://github.com/timhoffm/matplotlib/tree/grouped_bar
Conversation 113 https://github.com/matplotlib/matplotlib/pull/28560
Commits 8 https://github.com/matplotlib/matplotlib/pull/28560/commits
Checks 38 https://github.com/matplotlib/matplotlib/pull/28560/checks
Files changed https://github.com/matplotlib/matplotlib/pull/28560/files
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
ENH: Add grouped_bar() method https://github.com/matplotlib/matplotlib/pull/28560/files#top
Show all changes 8 commits https://github.com/matplotlib/matplotlib/pull/28560/files
fea06c9 ENH: Add grouped_bar() method timhoffm Jul 13, 2024 https://github.com/matplotlib/matplotlib/pull/28560/commits/fea06c94baa25b64c33fc3acbc214c32cecc4ac0
556895d Add tests for grouped_bar() timhoffm Jan 23, 2025 https://github.com/matplotlib/matplotlib/pull/28560/commits/556895dd9f22fd6d660cadbbf74b309df08c30f1
900ace5 Simplify "Grouped bar chart with labels" using grouped_bar() timhoffm Jan 22, 2025 https://github.com/matplotlib/matplotlib/pull/28560/commits/900ace552775dd93bfdef309c5b6a591feeac814
7fa82d7 Apply suggestions from code review timhoffm Jan 23, 2025 https://github.com/matplotlib/matplotlib/pull/28560/commits/7fa82d7ed9bdbf2934e0b37bd70b3f8e960310b4
8cf06c4 Docstring wording timhoffm Feb 1, 2025 https://github.com/matplotlib/matplotlib/pull/28560/commits/8cf06c487882f0270cb72810e56b7313603f63e3
a4ed768 Update lib/matplotlib/axes/_axes.py timhoffm Feb 5, 2025 https://github.com/matplotlib/matplotlib/pull/28560/commits/a4ed768b184a28a1725f4ffe2c0c2d963bc0ac52
d9aa5f6 Add test for grouped_bar() return value timhoffm Jun 2, 2025 https://github.com/matplotlib/matplotlib/pull/28560/commits/d9aa5f64bae90654b05560afde48a2226f454e99
e0afe74 Apply suggestions from code review timhoffm Jun 2, 2025 https://github.com/matplotlib/matplotlib/pull/28560/commits/e0afe743127b4462df362148ba63537aa7980132
Clear filters https://github.com/matplotlib/matplotlib/pull/28560/files
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
grouped_bar.py https://github.com/matplotlib/matplotlib/pull/28560/files#diff-f91f81f873a03b6d0616cf14af8c1e1baaca91eb9f539695ce319d7c850e9b2b
axes_api.rst https://github.com/matplotlib/matplotlib/pull/28560/files#diff-a287c3691b3efc4a40b816ce73137371ef6a7d490a648ae792b33197849d5ed9
pyplot_summary.rst https://github.com/matplotlib/matplotlib/pull/28560/files#diff-c0ea5ed3d9b3c117e5d0f8d07651c745583080ee8daae4ca291a21a998af94f8
grouped_bar.rst https://github.com/matplotlib/matplotlib/pull/28560/files#diff-a051ee396b510474927be50fba64649f09dc91101c362acc2b970d986d74a9e3
barchart.py https://github.com/matplotlib/matplotlib/pull/28560/files#diff-5b75d7dc3569ba7fb3d288d131b83eddb4a6a4fb9ecfc805763009934bc46d6a
_axes.py https://github.com/matplotlib/matplotlib/pull/28560/files#diff-608e2a1bf3d32fd631b0763599a3334d59822c11cb4fec1fa7398c9714592900
_axes.pyi https://github.com/matplotlib/matplotlib/pull/28560/files#diff-eadd15a7040334f239a70a5be507c694c92b6e7b709de5eadd2ee53231200215
pyplot.py https://github.com/matplotlib/matplotlib/pull/28560/files#diff-d1edb5a528e7423f485b24cac2083d05d365a19352f886bf15af3ef442bdda92
grouped_bar.png https://github.com/matplotlib/matplotlib/pull/28560/files#diff-d44c8fcaa9c98b3761b922176ebcbafdc623174de14e9d5107983801df418ac9
test_axes.py https://github.com/matplotlib/matplotlib/pull/28560/files#diff-ef5144bd27a700deb760ef56ccf51dc6fcfe86723f9ffa84df7f024985bf3ee7
boilerplate.py https://github.com/matplotlib/matplotlib/pull/28560/files#diff-09c5477c0e5f014a9c78894516d07d106d6a19413983879eeb66730e1767c819
doc/_embedded_plots/grouped_bar.pyhttps://github.com/matplotlib/matplotlib/pull/28560/files#diff-f91f81f873a03b6d0616cf14af8c1e1baaca91eb9f539695ce319d7c850e9b2b
View file https://github.com/timhoffm/matplotlib/blob/e0afe743127b4462df362148ba63537aa7980132/doc/_embedded_plots/grouped_bar.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/matplotlib/matplotlib/pull/28560/{{ revealButtonHref }}
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
doc/api/axes_api.rsthttps://github.com/matplotlib/matplotlib/pull/28560/files#diff-a287c3691b3efc4a40b816ce73137371ef6a7d490a648ae792b33197849d5ed9
View file https://github.com/timhoffm/matplotlib/blob/e0afe743127b4462df362148ba63537aa7980132/doc/api/axes_api.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/matplotlib/matplotlib/pull/28560/{{ revealButtonHref }}
https://github.com/matplotlib/matplotlib/pull/28560/files#diff-a287c3691b3efc4a40b816ce73137371ef6a7d490a648ae792b33197849d5ed9
https://github.com/matplotlib/matplotlib/pull/28560/files#diff-a287c3691b3efc4a40b816ce73137371ef6a7d490a648ae792b33197849d5ed9
doc/api/pyplot_summary.rsthttps://github.com/matplotlib/matplotlib/pull/28560/files#diff-c0ea5ed3d9b3c117e5d0f8d07651c745583080ee8daae4ca291a21a998af94f8
View file https://github.com/timhoffm/matplotlib/blob/e0afe743127b4462df362148ba63537aa7980132/doc/api/pyplot_summary.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/matplotlib/matplotlib/pull/28560/{{ revealButtonHref }}
https://github.com/matplotlib/matplotlib/pull/28560/files#diff-c0ea5ed3d9b3c117e5d0f8d07651c745583080ee8daae4ca291a21a998af94f8
https://github.com/matplotlib/matplotlib/pull/28560/files#diff-c0ea5ed3d9b3c117e5d0f8d07651c745583080ee8daae4ca291a21a998af94f8
doc/users/next_whats_new/grouped_bar.rsthttps://github.com/matplotlib/matplotlib/pull/28560/files#diff-a051ee396b510474927be50fba64649f09dc91101c362acc2b970d986d74a9e3
View file https://github.com/timhoffm/matplotlib/blob/e0afe743127b4462df362148ba63537aa7980132/doc/users/next_whats_new/grouped_bar.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/matplotlib/matplotlib/pull/28560/{{ revealButtonHref }}
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
galleries/examples/lines_bars_and_markers/barchart.pyhttps://github.com/matplotlib/matplotlib/pull/28560/files#diff-5b75d7dc3569ba7fb3d288d131b83eddb4a6a4fb9ecfc805763009934bc46d6a
View file https://github.com/timhoffm/matplotlib/blob/e0afe743127b4462df362148ba63537aa7980132/galleries/examples/lines_bars_and_markers/barchart.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/matplotlib/matplotlib/pull/28560/{{ revealButtonHref }}
https://github.com/matplotlib/matplotlib/pull/28560/files#diff-5b75d7dc3569ba7fb3d288d131b83eddb4a6a4fb9ecfc805763009934bc46d6a
https://github.com/matplotlib/matplotlib/pull/28560/files#diff-5b75d7dc3569ba7fb3d288d131b83eddb4a6a4fb9ecfc805763009934bc46d6a
https://github.com/matplotlib/matplotlib/pull/28560/files#diff-5b75d7dc3569ba7fb3d288d131b83eddb4a6a4fb9ecfc805763009934bc46d6a
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
Please reload this pagehttps://github.com/matplotlib/matplotlib/pull/28560/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.