matplotlib imshow() 什么都不做

maptplotlib imshow() does nothing

我最近安装了 Anaconda 发行版(sudo,在 /usr/lib 下)。

但是,当尝试执行以下行时:

from matplotlib import pyplot
from numpy import zeros
pyplot.imshow(zeros((100, 100)))

没有任何反应(我希望看到黑屏)。完全没有错误。

我错过了什么?

制作完成后,您需要告诉 matplotlib show 绘图(或将图形保存到文件中)。

要在屏幕上显示绘图,请尝试在 imshow 行之后添加 pyplot.show()

要保存到文件,请尝试 pyplot.savefig('myfig.png')

如果您想查看 plotimshow,请通过以下方式激活交互模式:

matplotlib.pyplot.ion()

这样您就不必每次都show()看到剧情更新了。

matplotlib.pyplot.ioff()

将关闭交互模式。交互模式会减慢程序速度,因此当您要绘制很多内容时,不建议使用 ion()