imshow()的图形太小了

时间:2021-10-21 20:21:39

I'm trying to visualize a numpy array using imshow() since it's similar to imagesc() in Matlab.

我尝试使用imshow()来可视化一个numpy数组,因为它与Matlab中的imagesc()相似。

imshow(random.rand(8, 90), interpolation='nearest')

The resulting figure is very small at the center of the grey window, while most of the space is unoccupied. How can I set the parameters to make the figure larger? I tried figsize=(xx,xx) and it's not what I want. Thanks!

得到的图形在灰色窗口的中心非常小,而大部分空间是空的。如何设置参数使图形更大?我尝试过figsize=(xx,xx),但这不是我想要的。谢谢!

imshow()的图形太小了

3 个解决方案

#1


75  

If you don't give an aspect argument to imshow, it will use the value for image.aspect in your matplotlibrc. The default for this value in a new matplotlibrc is equal. So imshow will plot your array with equal aspect ratio.

如果不给出一个方面参数来imshow,它将使用image的值。在你的matplotlibrc方面。新matplotlibrc中的这个值的默认值是相等的。imshow将用等纵横比绘制数组。

If you don't need an equal aspect you can set aspect to auto

如果不需要相等的方面,可以将方面设置为auto

imshow(random.rand(8, 90), interpolation='nearest', aspect='auto')

which gives the following figure

哪个给出了下面的数字

imshow()的图形太小了

If you want an equal aspect ratio you have to adapt your figsize according to the aspect

如果你想要等高宽比,你必须根据高来调整你的外形尺寸

fig, ax = subplots(figsize=(18, 2))
ax.imshow(random.rand(8, 90), interpolation='nearest')
tight_layout()

which gives you:

它给你:

imshow()的图形太小了

#2


9  

That's strange, it definitely works for me:

这很奇怪,对我来说很有用:

figure(figsize = (20,2))
imshow(random.rand(8, 90), interpolation='nearest')

I am using the "MacOSX" backend, btw.

我使用的是“MacOSX”后端,顺便说一下。

#3


1  

I'm new to python too. Here is something that looks like will do what you want to

我对python也不熟。这里有一些看起来可以做你想做的事情

axes([0.08, 0.08, 0.94-0.08, 0.94-0.08]) #[left, bottom, width, height]
axis('scaled')`

I believe this decides the size of the canvas.

我相信这决定了画布的大小。

#1


75  

If you don't give an aspect argument to imshow, it will use the value for image.aspect in your matplotlibrc. The default for this value in a new matplotlibrc is equal. So imshow will plot your array with equal aspect ratio.

如果不给出一个方面参数来imshow,它将使用image的值。在你的matplotlibrc方面。新matplotlibrc中的这个值的默认值是相等的。imshow将用等纵横比绘制数组。

If you don't need an equal aspect you can set aspect to auto

如果不需要相等的方面,可以将方面设置为auto

imshow(random.rand(8, 90), interpolation='nearest', aspect='auto')

which gives the following figure

哪个给出了下面的数字

imshow()的图形太小了

If you want an equal aspect ratio you have to adapt your figsize according to the aspect

如果你想要等高宽比,你必须根据高来调整你的外形尺寸

fig, ax = subplots(figsize=(18, 2))
ax.imshow(random.rand(8, 90), interpolation='nearest')
tight_layout()

which gives you:

它给你:

imshow()的图形太小了

#2


9  

That's strange, it definitely works for me:

这很奇怪,对我来说很有用:

figure(figsize = (20,2))
imshow(random.rand(8, 90), interpolation='nearest')

I am using the "MacOSX" backend, btw.

我使用的是“MacOSX”后端,顺便说一下。

#3


1  

I'm new to python too. Here is something that looks like will do what you want to

我对python也不熟。这里有一些看起来可以做你想做的事情

axes([0.08, 0.08, 0.94-0.08, 0.94-0.08]) #[left, bottom, width, height]
axis('scaled')`

I believe this decides the size of the canvas.

我相信这决定了画布的大小。