问题描述
我正在尝试使用 imshow() 来可视化一个 numpy 数组,因为它类似于 Matlab 中的 imagesc().
I'm trying to visualize a numpy array using imshow() since it's similar to imagesc() in Matlab.
imshow(random.rand(8, 90), interpolation='nearest')
生成的图形在灰色窗口的中心非常小,而大部分空间都未被占用.如何设置参数使图形变大?我试过 figsize=(xx,xx) 这不是我想要的.谢谢!
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!
推荐答案
如果你没有给 imshow
一个 aspect
参数,它会使用 aspect
的值matplotlibrc
中的 code>image.aspect.新 matplotlibrc
中此值的默认值是 equal
.所以 imshow
将以相同的纵横比绘制您的数组.
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.
如果您不需要相等的方面,您可以将 aspect
设置为 auto
If you don't need an equal aspect you can set aspect
to auto
imshow(random.rand(8, 90), interpolation='nearest', aspect='auto')
给出下图
如果你想要一个相等的纵横比,你必须根据纵横比调整你的figsize
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()
它给了你:
这篇关于imshow() 的图太小了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!