Add group_positions attribute to BarContainer - #32282
Conversation
|
Thank you for opening your first PR into Matplotlib! If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process. You can also join us on discourse chat for real-time discussion. For details on testing, writing docs, and our review process, please see the developer guide. We strive to be a welcoming and open project. Please follow our Code of Conduct. |
|
Thanks for the PR! can you please fill out the AI disclosure bit? Would it also be useful to then provide more information, like bar width, given width also seems to be calculated internally? |
Return the list of bar widths (perpendicular to height), mirroring bottoms, tops, and position_centers. Works consistently for all bar plots across Matplotlib.
|
Thanks for the review! I've updated the PR description with the AI disclosure section. Yes, a |
timhoffm
left a comment
There was a problem hiding this comment.
This is a reasonable addition. Thanks"
|
Thanks for the quick turn around. This just needs a what's new entry before it can be merged https://matplotlib.org/devdocs/devel/api_changes.html#release-notes |
|
Thanks. I just added an entry. |
|
Is there another wording you'd prefer to use?
…On Mon, 7 Sep 2026 at 20:16, hannah ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In doc/release/next_whats_new/new_barcontainer_properties.rst
<#32282 (comment)>
:
> @@ -0,0 +1,16 @@
+``BarContainer`` properties and attributes
+------------------------------------------
+
+`.BarContainer` gained a new `~.BarContainer.widths` property. It returns a
+list of the widths of the individual bars in the container (the dimension
+perpendicular to the bar height).
+
+For standard bar plots (e.g. created by `.Axes.bar` or `.Axes.barh`), this
+reflects the width of each bar in the plot. For grouped bar plots (e.g. created
+by `.Axes.grouped_bar`), each `~.BarContainer` represents a single dataset
I think "represents a single dataset" is a but hard to follow and sorry
for all the back and forth here, just wanna make sure it's clear.
—
Reply to this email directly, view it on GitHub
<#32282?email_source=notifications&email_token=AGZQNNZB6SMSNJO7BVLNIKL5N4CPNA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKMJTGQ3TONRWGA32M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KYZTPN52GK4S7MNWGSY3L#pullrequestreview-5134776607>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AGZQNN7QSXU7Z2UQ7UWF3X35N4CPNAVCNFSNUABDKJSXA33TNF2G64TZHMYTGOBVGEZDEO2JONZXKZJ3GUZTGOBZGA3TAMJUUF3AE>
.
Triage notifications, keep track of coding agent tasks and review pull
requests on the go with GitHub Mobile for iOS
<https://github.com/notifications/mobile/ios/AGZQNN43UDTRQG3AY2T6A4T5N4CPNA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKMJTGQ3TONRWGA32M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2KUZTPN52GK4S7NFXXG>
and Android
<https://github.com/notifications/mobile/android/AGZQNNYQX2CFI3GHEOMG4FL5N4CPNA5CNFSNUABKM5UWIORPF5TWS5BNNB2WEL2QOVWGYUTFOF2WK43UKJSXM2LFO4XTKMJTGQ3TONRWGA32M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2K4ZTPN52GK4S7MFXGI4TPNFSA>.
Download it today!
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
The failure in circleci is due to |
|
Thanks for the contribution and putting up w/ the nits on the release notes! |
Add
group_positionsattribute toBarContainer.Motivation and Context
In
Axes.grouped_bar(),BarContainerinstances are placed at calculated fractional coordinates (lefts). However, the resultingBarContainerinstances inax.containersdo not record the shared categoricalgroup_centersfrom which those fractional offsets were derived.This makes it difficult for downstream converters (such as interactive exporters like Plotly/
matplotlylib) and inspection tools to access the intended group coordinates without resorting to reverse-engineering layout geometry.Following the existing pattern of
BarContainer.datavalues(added forbar_label) andBarContainer.orientation:ax.bar()containers retaingroup_positions = None.Axes.grouped_bar()havebc.group_positions = group_centers.Proposed Changes
group_positions=Noneparameter and attribute toBarContainerinlib/matplotlib/container.pyand its type stubcontainer.pyi.Axes.grouped_bar(), setbc.group_positions = group_centers.bc.group_positionsintest_grouped_bar_return_value.Backwards Compatibility
100% backwards-compatible. Standard
ax.bar()calls default togroup_positions = None.AI Disclosure
AI was used to gain understanding of the existing code and to proof-read the PR description.