Python. Matplotlib倒像 [英] Python. Matplotlib inverted image
问题描述
我不知道这里出了什么问题.
I haven't an idea what is wrong here.
import matplotlib.pyplot as plt
im = plt.imshow(plt.imread('tas.png'))
plt.show()
并且Y轴已反转.
所以我写了一个参数origin='lower'
.
And the Y axis has inverted.
So I wrote an argument origin='lower'
.
im = plt.imshow(plt.imread('tas.png'), origin='lower')
plt.show()
还有我所得到的.
Y轴正常返回,但现在图像已反转.
And what I have got.
The Y axis came normally, but image now has been inverted.
另外,当我尝试重新缩放X轴和Y轴时,图像没有变小,仅切出了一块.
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.
推荐答案
您正在遇到有关图像编码方式的伪像.由于历史原因,图像的原点位于左上角(就像在2D数组上建立索引一样……想象一下仅打印一个数组,数组的第一行就是图像的第一行,依此类推.)
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.)
使用origin=lower
有效翻转图像(如果要在图像顶部绘制内容,这很有用).如果要将图像翻转为朝上"并且 以底部为原点,则需要翻转图像,然后再调用imshow
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()
这篇关于Python. Matplotlib倒像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!