gpt4 book ai didi

python - show() 不再重绘

转载 作者:行者123 更新时间:2023-12-04 14:43:10 25 4
gpt4 key购买 nike

我在 linux 中工作,我不知道为什么使用 python 和 matplotlib 命令只能绘制一次我想要的图表。我第一次调用 show() 时绘制了图,没有任何问题,但第二次和以后没有。

我关闭了显示两次通话之间图表的窗口。您知道为什么要修复它吗?

谢谢AFG

from numpy import *from pylab import *data = array( [ 1,2,3,4,5] )plot(data)[<matplotlib.lines.Line2D object at 0x90c98ac>]show() # this call shows me a plot#..now I close the window...data = array( [ 1,2,3,4,5,6] )plot(data)[<matplotlib.lines.Line2D object at 0x92dafec>]show()  # this one doesn't shows me anything

最佳答案

在 Windows 中这很完美:

from pylab import *
plot([1,2,3,4])
[<matplotlib.lines.Line2D object at 0x03442C10>]
#close window here
plot([1,2,3,4])
[<matplotlib.lines.Line2D object at 0x035BC570>]

你试过吗:

from matplotlib import interactive
interactive(True)

有时 matplotlib 会产生一些令人头疼的问题,因为我们必须记住在 matplotlibrc 中设置了一些选项(例如后端或交互参数)。如果您使用来自不同编辑器(IDLE-tk、pycrust-wxpython)的 matplotlib 或交替使用脚本进行交互,那么您必须考虑到在一种模式下工作的配置可能会给您在另一种模式下带来问题,并且必须以编程方式进行修改或使用专用配置文件。

我给出的示例直接工作(没有 show()),因为在 matplotlibrc 中我将交互设置为默认 True

关于python - show() 不再重绘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2789180/

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