Python 相当于matplotlib中matlab的imagesc?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16655438/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 23:17:36  来源:igfitidea点击:

Equivalent to matlab's imagesc in matplotlib?

pythonimagematlabmatplotlib

提问by Matt

I am coming to Python and numpy and matplotlib from a Matlab background. One function in matlab that I use all the time is imagesc. Is there an exact equivalent to this somewhere in matplotlib? I know about imshowand pcolor, but the first doesn't allow you to easily set the units of the axes like imagesc, and the second makes you set the x- and y-coordinates of the boundaries of the pixels, rather than the centers of the pixels, which I do not find intuitive.

我从 Matlab 背景来到 Python、numpy 和 matplotlib。我一直使用的 matlab 中的一个函数是imagesc. 在 matplotlib 的某处是否有与此完全相同的内容?我知道imshowand pcolor,但第一个不允许您轻松设置轴的单位,例如imagesc,第二个让您设置像素边界的 x 和 y 坐标,而不是像素的中心,我觉得这不直观。

Basically, if I have an image that I want to display with x- and y-axis labels that are not pixel numbers but are numerical, like distance in mm, what is the easiest way to do it in matplotlib?

基本上,如果我想用 x 轴和 y 轴标签显示图像,这些标签不是像素数而是数字,例如以毫米为单位的距离,那么在 matplotlib 中最简单的方法是什么?

采纳答案by tacaswell

You want the extentkwarg

你想要extent夸格

ax.imshow(data, extent=[0, 1, 0, 1])

See Imshow: extent and aspectfor a more detailed example.

有关更详细的示例,请参阅Imshow:范围和方面