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 8.3k times
115
pratikm
- 3,614
- 6
- 22
- 23
4 Answers
221
Specify the keyword argument origin='lower' or origin='upper' in your call to imshow.
wim
- 302,178
- 90
- 548
- 690
-
why 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
-
probably 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
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
- 616
- 6
- 8
0
Use ax.invert_yaxis() to invert the y-axis, or ax.invert_xaxis() to invert the x-axis.
Nirmal
- 1,009
- 2
- 12
- 21
-15
add .T after the data you want to plot
plt.imshow(data.T)
This will "transpose" the data
Ben Pickering
- 43
- 1
- 8
-
1This assumes that the data being shown is a Numpy array and not a list or other structure. Specifically by calling `.T` means calling `numpy.ndarray.T` – RegularlyScheduledProgramming Sep 13 '16 at 15:55
-
19