I wanted the imshow()
function in matplotlib.pyplot
to display images the opposite way, i.e upside down. Is there a simple way to do this?
Asked
Active
Viewed 1e+01k times
135

pratikm
- 4,034
- 7
- 25
- 23
4 Answers
252
Specify the keyword argument origin='lower'
or origin='upper'
in your call to imshow
.

wim
- 338,267
- 99
- 616
- 750
-
3why does default differ on different machines? Is there a way to set the default? Thanks for this answer nonetheless, in the past I tried to fix this by using matrix flips and stuff. This is much easier! – Milla Well Mar 04 '13 at 11:49
-
2probably because of different versions of pyplot (they changed the convention somewhere from 0,0 being top-left to bottom-left) – wim Mar 04 '13 at 12:28
-
1What if you want to move it clockwise. – Rahmi Pruitt Nov 25 '19 at 20:44
-
@RahmiPruitt See [Matplotlib rotate image file by X degrees](https://stackoverflow.com/q/31401812/674039) – wim Mar 11 '20 at 15:39
4
Use ax.invert_yaxis()
to invert the y-axis, or ax.invert_xaxis()
to invert the x-axis.

Nirmal
- 1,285
- 2
- 13
- 23
1
You can use the extent
argument. For example, if X values range from -10 and 10 and Y values range from -5 to 5, you should pass extent=(-10,10,-5,5)
to imshow()
.

Nbarjest
- 691
- 6
- 9
-
Rather than mirroring the image vertically, it mirrors the axis marks. While not an answer the question it can be an alternative in some cases. In addition it remaps the axis to a new range instead of the pixel count used by `imshow`. – mins Oct 28 '22 at 10:38
0
Rotate image with NumPy: np.rot90()
Flip image with NumPy: np.flip()
e.g.
plt.imshow(np.flip(img))
plt.show()
OR
plt.imshow(np.rot90())
plt.show()

AbdulHafeez
- 9
- 2