I haven't an idea what is wrong here.
import matplotlib.pyplot as plt
im = plt.imshow(plt.imread('tas.png'))
plt.show()
And the Y axis has inverted.
So I wrote an argument origin='lower'
.
im = plt.imshow(plt.imread('tas.png'), origin='lower')
plt.show()
And what I have got.
The Y axis came normally, but image now has been inverted.
Also when i try to re-scale axis X and Y, the image hasn't got smaller, only cut out piece.
Thank you in advance. I would be so grateful for some help.
Use ax. invert_yaxis() to invert the y-axis, or ax. invert_xaxis() to invert the x-axis.
Matplotlib invert x and y axisBy using invert_xaxis() and invert_yaxis() method we can flip the x-axis and y-axis respectively. In the above example, we import numpy and matplotlib libraries. After this, we define data on x and y coordinates. By using the plt.
Practical Data Science using Python Make a list of data points and colors. Plot the bars with data and colors, using bar() method. Using FuncAnimation() class, make an animation by repeatedly calling a function, animation, that sets the height of the bar and facecolor of the bars.
Use xticks and yticks method to specify the ticks on the axes with x and y ticks data points respectively.
You are running into an artifact of how images are encoded. For historical reasons, the origin of an image is the top left (just like the indexing on 2D array ... imagine just printing out an array, the first row of your array is the first row of your image, and so on.)
Using origin=lower
effectively flips your image (which is useful if you are going to be plotting stuff on top of the image). If you want to flip the image to be 'right-side-up' and have the origin of the bottom, you need to flip your image before calling imshow
import numpy as np
im = plt.imshow(np.flipud(plt.imread('tas.png')), origin='lower')
plt.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With