To reverse a Matplotlib y-axis over a known range, call ax.set_ylim(high, low). To reverse its direction without specifying new bounds, use ax.yaxis.set_inverted(True). For an image that looks upside down, first check imshow‘s origin, image extent, and the Axes limits: image row placement and axis direction are related but distinct.
Choose the method that matches what you want to change
| Goal | Use | Effect |
|---|---|---|
| Set a known range in reverse order | ax.set_ylim(high, low) |
Sets the bounds and their direction. |
| Reverse direction while keeping the current limits or autoscaling behavior | ax.yaxis.set_inverted(True) |
Changes the axis inversion state without supplying new endpoints. |
| Choose whether image rows run top-down or bottom-up | imshow(..., origin="upper") or origin="lower" |
Controls how rows fill the image extent; the extent and Axes limits also affect its screen orientation. |
Reverse the right-side y-axis created by twinx() |
Call set_ylim or set_inverted on the returned twin Axes. |
Changes that Axes’ independent y-axis. |
Reverse a y-axis with set_ylim
When you know the numeric bounds, pass them in descending order. For example, to put 0 at the top and 10 at the bottom:
As an Amazon Associate I earn from qualifying purchases.
ax.set_ylim(10, 0)
This sets both the range and its direction. Matplotlib’s current stable inversion gallery recommends swapping limit values when you are setting explicit bounds. See the Matplotlib Inverted axis example.
Invert direction without supplying new bounds
If you want to keep the existing limits or autoscaling behavior and change only the direction, set the inversion state on the y-axis:
#1 Best Overall
ax.yaxis.set_inverted(True)
The Matplotlib 3.11.2 inversion gallery identifies Axis.set_inverted as the method for changing direction without modifying limits. In the current stable API reference, Axes.invert_yaxis() is marked discouraged; use set_inverted(True) for this purpose, or reversed set_ylim when you intend to set explicit bounds. See the inversion gallery and Axes.invert_yaxis API reference.
Fix an upside-down imshow image
imshow‘s origin setting controls how array rows are placed within the image extent. With origin="upper", the first array row is at the top:
Rank #2
ax.imshow(image, origin="upper")
The default is configured by rcParams["image.origin"], whose documented value is 'upper'. The image’s extent maps it into data coordinates, while the Axes limits also influence its displayed orientation. Consequently, an image that appears top-down does not necessarily need an additional y-axis inversion. Check the origin, extent, and limits together before changing direction. The Matplotlib 3.10.7 guide explains these interactions in Origin and extent in imshow.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsInvert the y-axis of a twinx() plot
twinx() creates a second Axes that shares the x-axis but has its own y-axis, typically shown on the right. Apply the change to the Axes whose y scale you want to reverse:
Rank #3
ax_right = ax_left.twinx()
ax_right.set_ylim(100, 0) # reverses the right-side y-axis
If the two y scales have different ranges, set each Axes’ range independently. The Matplotlib twinx API reference documents the shared x-axis and independent y-axis.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What changes when axes share y
Axes joined with sharey synchronize their view limits. Changing the y limits on one shared Axes therefore changes the others as well; this differs from twinx(), whose y-axes are independent. See Matplotlib’s Shared axis example.
Quick Recap
Rank #4
Check the result
- Use reversed
set_ylimendpoints when you want to specify a particular reversed range. - Use
ax.yaxis.set_inverted(True)when direction should change without supplying new limits. - For images, inspect
origin,extent, and the Axes limits before applying an additional inversion. - For
twinx(), make the change on the returned twin Axes if the right-side scale is the one you intend to reverse.
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →




