Python Inverted Matplotlib

I do not know what is wrong here.

import matplotlib.pyplot as plt im = plt.imshow(plt.imread('tas.png')) plt.show() 

And the Y axis is inverted.
So I wrote the argument origin='lower' .

 im = plt.imshow(plt.imread('tas.png'), origin='lower') plt.show() 

And what I have.
The Y axis went fine, but the image is now inverted.

Also, when I try to re-scale the X and Y axes, the image did not shrink, but only cut a piece.

Thanks in advance. I would be very grateful for the help.

+7
source share
1 answer

You are encountering an artifact of image encoding. For historical reasons, the origin of the image is the top left (just like indexing in a 2D array ... imagine, just by printing an array, the first line of your array is the first line of your image, etc.).

Using origin=lower effectively flips your image (which is useful if you are going to draw material on top of the image). If you want to flip the image so that it is β€œtop right” and has the beginning of the bottom, you need to flip the image before calling imshow

  import numpy as np im = plt.imshow(np.flipud(plt.imread('tas.png')), origin='lower') plt.show() 
+15
source

All Articles