简体   繁体   English

matplotlib.imshow 坐标可以从 0 而不是 -0.5 开始吗?

[英]Can matplotlib.imshow coordinates start at 0 instead of -0.5?

I'm trying to draw a box on a scaled image, and I notice that when the image is very small, the box seems to be drawn with an offset (see second row of the image):我试图在缩放的图像上绘制一个框,我注意到当图像非常小时,该框似乎是用偏移量绘制的(参见图像的第二行):

在此处输入图片说明

This behavior seems to be because I'm expecting the top left of the top left pixel to be aligned with the point (0, 0), but it seems that this point is actually aligned with the middle of the pixel.这种行为似乎是因为我期望左上角像素的左上角与点 (0, 0) 对齐,但似乎该点实际上与像素的中间对齐。 So, the coordinate of the top left corner of the image seems to actually be (-0.5, -0.5).因此,图像左上角的坐标实际上似乎是 (-0.5, -0.5)。

Is there a way to change the behavior of matplotlib.imshow so coordinates are aligned with the top left of each pixel instead of the centers?有没有办法改变 matplotlib.imshow 的行为,使坐标与每个像素的左上角而不是中心对齐?

The imshow extent is what you need. imshow 范围正是您所需要的。

Use extent=(0, numcols, 0, numrows) instead of the default (-0.5, numcols-0.5, -0.5, numrows-0.5) .使用extent=(0, numcols, 0, numrows)而不是默认值(-0.5, numcols-0.5, -0.5, numrows-0.5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM