Invert image displayed by imshow in matplotlib

PythonImageMatplotlib

Python Problem Overview


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?

Python Solutions


Solution 1 - Python

Specify the keyword argument origin='lower' or origin='upper' in your call to imshow.

Solution 2 - Python

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().

Solution 3 - Python

Use ax.invert_yaxis() to invert the y-axis, or ax.invert_xaxis() to invert the x-axis.

Solution 4 - Python

add .T after the data you want to plot

plt.imshow(data.T)

This will "transpose" the data

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionpratikm View Question on Stackoverflow
Solution 1 - PythonwimView Answer on Stackoverflow
Solution 2 - PythonNbarjestView Answer on Stackoverflow
Solution 3 - PythonNirmalView Answer on Stackoverflow
Solution 4 - PythonBen PickeringView Answer on Stackoverflow