gpt4 book ai didi

python - Matplotlib 没有显示绘图

转载 作者:行者123 更新时间:2023-12-01 04:19:00 25 4
gpt4 key购买 nike

我不知道为什么我的 matplotlib 没有显示绘图,也没有错误。我认为我在安装时遗漏了一些东西,因为在 IPython 笔记本中,使用 %mayplotlib inline 指令的 QtIpython 没有问题,但从终端或脚本运行时没有显示任何内容。有什么想法吗??

例如,在我运行的 QtIPython 和 Ipython 笔记本中

%matplotlib inline
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.plot([1,2,3,4,5,6,7,8,9,0],[2,3,4,5,6,7,8,9,0,11], '-r')
ax.grid()
plt.show()

绘图显示“Ok”!

但是在一个简单的脚本中

import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111, aspect='equal')
ax.plot([1,2,3,4,5,6,7,8,9,0],[2,3,4,5,6,7,8,9,0,11], '-r')
ax.grid()
plt.show()

没有显示任何内容

最佳答案

如果您在 IPython 笔记本中内联使用 matplotlib,则会自动显示绘图。如果您在脚本中绘制内容,则必须在末尾添加 plt.show() 才能实际显示图形。在终端中,您还可以使用 plt.ion() 打开交互模式。

关于python - Matplotlib 没有显示绘图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33945560/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com