Title: [MNT]: Refactor grouped_bar orientation logic using shared common_kwargs · Issue #30729 · matplotlib/matplotlib · GitHub
Open Graph Title: [MNT]: Refactor grouped_bar orientation logic using shared common_kwargs · Issue #30729 · matplotlib/matplotlib
X Title: [MNT]: Refactor grouped_bar orientation logic using shared common_kwargs · Issue #30729 · matplotlib/matplotlib
Description: Summary In the Axes.grouped_bar() implementation, the code currently passes repetitive keyword arguments separately for vertical and horizontal orientations. Tim Hoffmann suggested a more maintainable approach by introducing a shared com...
Open Graph Description: Summary In the Axes.grouped_bar() implementation, the code currently passes repetitive keyword arguments separately for vertical and horizontal orientations. Tim Hoffmann suggested a more maintaina...
X Description: Summary In the Axes.grouped_bar() implementation, the code currently passes repetitive keyword arguments separately for vertical and horizontal orientations. Tim Hoffmann suggested a more maintaina...
Opengraph URL: https://github.com/matplotlib/matplotlib/issues/30729
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[MNT]: Refactor grouped_bar orientation logic using shared common_kwargs","articleBody":"### Summary\n\nIn the Axes.grouped_bar() implementation, the code currently passes repetitive keyword arguments separately for vertical and horizontal orientations.\n\nTim Hoffmann suggested a more maintainable approach by introducing a shared common_kwargs dictionary to consolidate repeated parameters such as align, label, color, and hatch.\n\n\nCurrent Code Snippet:: \n\n```\nif orientation == \"vertical\":\n bc = self.bar(lefts, hs, width=bar_width, align=\"edge\",\n label=label, color=color, hatch=hatch_pattern, **kwargs)\nelse:\n bc = self.barh(lefts, hs, height=bar_width, align=\"edge\",\n label=label, color=color, hatch=hatch_pattern, **kwargs)\n```\n\nProposed Refactor::\n```\ncommon_kwargs = dict(align=\"edge\", label=label, color=color, hatch=hatch_pattern)\nif orientation == \"vertical\":\n bc = self.bar(lefts, hs, width=bar_width, **common_kwargs, **kwargs)\nelse:\n bc = self.barh(lefts, hs, height=bar_width, **common_kwargs, **kwargs)\n```\n\nBenefits\nEliminates redundant code across orientation branches.\nReduces likelihood of introducing inconsistencies or errors during future updates.\nMakes the code cleaner and easier to maintain.\nRemoves the need for a separate orientation-specific test since the logic path becomes symmetrical.\n\nReference:\nSuggestion from @timhoffm in PR ENH: Add broadcasted hatch to grouped_bar #30683 \n\n\n\n### Proposed fix\n\n```\ncommon_kwargs = dict(align=\"edge\", label=label, color=color, hatch=hatch_pattern)\nif orientation == \"vertical\":\n bc = self.bar(lefts, hs, width=bar_width, **common_kwargs, **kwargs)\nelse:\n bc = self.barh(lefts, hs, height=bar_width, **common_kwargs, **kwargs)\n```","author":{"url":"https://github.com/ilakkmanoharan","@type":"Person","name":"ilakkmanoharan"},"datePublished":"2025-11-05T02:15:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/30729/matplotlib/issues/30729"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a127ec64-ac2c-3f92-7a8b-1a781ab25534 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 99DC:1D60FB:7E6396:A8CC74:6A530832 |
| html-safe-nonce | 7303e6b016f59da5f1eeba32bd0730d450935b3fee6f034225c7b47b4b0eaf22 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OURDOjFENjBGQjo3RTYzOTY6QThDQzc0OjZBNTMwODMyIiwidmlzaXRvcl9pZCI6IjI1Mzg0MTYyOTMyMzQ4MDQ3ODYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e2470e6a7601ddb61495e4fd26dff9b850f5b8dc83f3d8de03f4fe6ccf17e1b3 |
| hovercard-subject-tag | issue:3588816807 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/matplotlib/matplotlib/30729/issue_layout |
| twitter:image | https://opengraph.githubassets.com/04cd99b22c750d266be27d5e294f4f09052918c9fd91a1ce8838a881afb0a6c2/matplotlib/matplotlib/issues/30729 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/04cd99b22c750d266be27d5e294f4f09052918c9fd91a1ce8838a881afb0a6c2/matplotlib/matplotlib/issues/30729 |
| og:image:alt | Summary In the Axes.grouped_bar() implementation, the code currently passes repetitive keyword arguments separately for vertical and horizontal orientations. Tim Hoffmann suggested a more maintaina... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ilakkmanoharan |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 07a982c1d40157c619b364352b704c3ce66bb332 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width