gpt4 book ai didi

python - matplotlib.pyplot/pylab 在 isinteractive() 时不更新图,使用 ipython -pylab

转载 作者:太空狗 更新时间:2023-10-29 16:54:08 25 4
gpt4 key购买 nike

<分区>

有很多关于 matplotlib、pylab、pyplot、ipython 的问题,如果您厌倦了看到这个问题,我很抱歉。我会尽量具体,因为我一直在查看人们的问题并查看 pyplot 和 pylab 的文档,但我仍然不确定我做错了什么。使用代码:

目标:每 0.5 秒绘制一个图形,并在调用绘图命令后立即更新图形。

我的编码尝试如下(在 ipython -pylab 上运行):


import time
ion()
x=linspace(-1,1,51)
plot(sin(x))
for i in range(10):
plot([sin(i+j) for j in x])
#see **
print i
time.sleep(1)
print 'Done'

It correctly plots each line, but not until it has exited the for loop. I have tried forcing a redraw by putting draw() where ** is, but that doesn't seem to work either. Ideally, I'd like to have it simply add each line, instead of doing a full redraw. If redrawing is required however, that's fine.

Additional attempts at solving:
just after ion(), tried adding hold(True) to no avail.
for kicks tried show() for **
The closest answer I've found to what I'm trying to do was at plotting lines without blocking execution, but show() isn't doing anything.

I apologize if this is a straightforward request, and I'm looking past something so obvious. For what it's worth, this came up while I was trying to convert matlab code from class to some python for my own use. The original matlab (initializations removed) which I have been trying to convert follows:


for i=1:time
plot(u)
hold on
pause(.01)
for j=2:n-1
v(j)=u(j)-2*u(j-1)
end
v(1)= pi
u=v
end

任何帮助,即使只是“查找 this_method”都会非常好,因此我至少可以缩小我的工作范围,找出如何使用该方法。如果有更多有用的信息,请告诉我。

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