Skip to content

Conversation

@rcomer
Copy link
Member

@rcomer rcomer commented Jan 15, 2026

PR summary

@github-actions github-actions bot added the Documentation: examples files in galleries/examples label Jan 15, 2026

ax.barh(people, performance, xerr=error, align='center')
ax.invert_yaxis() # labels read top-to-bottom
ax.yaxis.set_inverted(True) # labels read top-to-bottom
Copy link
Member

Choose a reason for hiding this comment

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

This is preferred to ax.invert_yaxis ? Not sure I understand that.

Copy link
Contributor

Choose a reason for hiding this comment

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

See https://github.com/matplotlib/matplotlib/pull/13330/changes#diff-23b7fa7a4b346c0e303ac8bc2158c701c855dc79256dff8bfadbaa9df62307e5: the problem of invert_yaxis is that it is brittle if you don't control the whole axes life-cycle, which easily occurs if your code ends up refactored in a separate function.

Copy link
Member

@jklymak jklymak Jan 15, 2026

Choose a reason for hiding this comment

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

"invert" means "to reverse in position, order, or relationship". It doesn't matter if the axis has been inverted before, it's just a toggle, so I don't see the brittleness

fig, ax = plt.subplots()
ax.plot(np.arange(10))
ax.invert_yaxis()
ax.invert_yaxis()

yields a yaxis that has 0 on the bottom and 9 on the top

@anntzer
Copy link
Contributor

anntzer commented Jan 15, 2026

I think this kind of minimal example should just use some made-up data (performance = [5, 7, 6, 4, 9]; error = [0.2, 0.4, 0.1, 0.6, 0.2]) rather that going through the bother of using a RNG.

@timhoffm
Copy link
Member

@rcomer thanks for immediately taking action on adding fixed data.

Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@timhoffm timhoffm merged commit 6208137 into matplotlib:main Jan 15, 2026
20 checks passed
@rcomer rcomer deleted the barh-modern branch January 15, 2026 17:41
@QuLogic QuLogic added this to the v3.11.0 milestone Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation: examples files in galleries/examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants