简体   繁体   English

交互式Matplotlib窗口未更新

[英]Interactive Matplotlib window not updating

I have a programme which creates an interactive matplotlib (well, pylab) figure, then waits for a raw_input while letting the user manipulate the plot to manually find the best data. 我有一个程序,该程序创建一个交互式matplotlib(好吧,pylab)图,然后等待raw_input,同时让用户操纵图来手动查找最佳数据。

import pylab as p
p.ion()
p.figure(1)
p.plot(x,y,'.')
cen=float(raw_input('Type centre:'))
dur=float(raw_input('Type duration:'))
depth=float(raw_input('Type depth:'))

If I run this on linux (matplotlib 1.4.3), it works as expected. 如果我在linux(matplotlib 1.4.3)上运行它,它将按预期工作。 Running this on my Mac (matplotlib 1.5.0) freezes the pylab window at it's first draw and doesn't let the interactive features work. 在我的Mac(matplotlib 1.5.0)上运行此命令会在第一次绘制时冻结pylab窗口,并且不允许交互式功能正常工作。 After something is entered into the raw_input, however, it draws all the preceding interactive clicks. 但是,在将某些内容输入raw_input后,它会绘制所有先前的交互式单击。 Any ideas? 有任何想法吗?

ion() and raw_input() do not work well together. ion()raw_input()不能很好地协同工作。 This is a known problem. 这是一个已知的问题。 In interactive mode pyplot.ion() is using an event handler to wait for keypresses. 在交互模式下, pyplot.ion()使用事件处理程序等待按键。 This breaks when raw_input takes over the input. raw_input接管输入时,这会中断。

You can make it a bit better by adding draw() or show() : 您可以通过添加draw()show()使它更好一点:

import pylab as p
p.ion()
p.figure(1)
p.plot(x,y,'.')
p.show()
cen=float(raw_input('Type centre:'))
dur=float(raw_input('Type duration:'))
depth=float(raw_input('Type depth:')) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM