【问题标题】:Interactive Matplotlib window not updating交互式 Matplotlib 窗口未更新
【发布时间】:2016-03-16 17:17:29
【问题描述】:

我有一个程序可以创建交互式 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:'))

如果我在 linux (matplotlib 1.4.3) 上运行它,它会按预期工作。在我的 Mac(matplotlib 1.5.0)上运行它会在第一次绘制时冻结 pylab 窗口,并且不会让交互功能起作用。然而,在 raw_input 中输入某些内容后,它会绘制所有前面的交互式点击。有什么想法吗?

【问题讨论】:

标签: python matplotlib


【解决方案1】:

ion()raw_input() 不能很好地协同工作。这是一个已知问题。在交互模式下pyplot.ion() 正在使用事件处理程序来等待按键。这会在 raw_input 接管输入时中断。

您可以通过添加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:')) 

【讨论】:

  • 不幸的是,这似乎无法解决问题。
猜你喜欢
  • 2013-07-24
  • 2014-06-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-25
  • 1970-01-01
相关资源
最近更新 更多