Skip to content

ENH: Add properties position_centers and tops to BarContainer #30226

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Jun 29, 2025

These will be useful if one wants to put additional things on the bars.

Noted in #30224 (comment), which this will simplify because instad of

    def center_top(rect):
        return rect.xy[0] + rect.get_width()/2, rect.xy[1] + rect.get_height()

    xy = np.array([center_top(r) for r in container.patches])
    ax.errorbar(xy[:,0], xy[:,1], yerr=yerr)

we can then simply do

    ax.errorbar(container.position_centers, container.tops, yerr=yerr)

Naming: The naming has to work for horizontal and vertical bars.

@timhoffm timhoffm force-pushed the barcontainer_props branch from 239dcf3 to 44e3dcd Compare June 29, 2025 22:17
@timhoffm timhoffm added this to the v3.11.0 milestone Jun 29, 2025
@timhoffm timhoffm force-pushed the barcontainer_props branch from 44e3dcd to df22b8a Compare June 30, 2025 14:37
@QuLogic
Copy link
Member

QuLogic commented Jul 31, 2025

Would starts/ends be better as directionally-independent names?

@timhoffm
Copy link
Member Author

I'm inclined to say no. starts/ends sound quite generic. If you talk in abstract shapes, a rectangle height would always be the y-direction. One can argue, but for bars, the height is a logical property to me and extents perpendicular to the baseline. For a horizontal bar, I would thus still describe the height as the value direction, i.e. then along the x-axis.

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor suggestion, otherwise a nice addition 👍

Could also consider adding a bottoms property to complement tops?

@timhoffm timhoffm force-pushed the barcontainer_props branch from df22b8a to 4325141 Compare August 2, 2025 01:11
@timhoffm
Copy link
Member Author

timhoffm commented Aug 2, 2025

bottoms added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants