【发布时间】:2013-06-14 20:08:07
【问题描述】:
我正在编写一个 python 脚本,其中我在对象 Plotter 中有以下方法:
import matplotlib.pyplot as plt
class Plotter:
def __init__(self):
self.nbfig = 0
def plot(self):
self.nbfig += 1
plt.figure(self.nbfig)
plt.plot(self.time, self.angle, 'b')
plt.ion()
plt.show()
当需要绘制某些东西时,实时 C++ 应用程序会调用 python 脚本(这就是我使用 plt.ion() 以便绘图在不同的线程中运行并且不会停止 c++ 应用程序的原因) 但是,有时c++应用需要刷新应用,调用如下方法:
def refresh(self):
if (self.nbfig > 0): #meaning the c++ app already plotted a figure
plt.close()
此方法有效地关闭了我绘制角度的 matplotlib 窗口。但是,当它第二次调用 plot 方法(如上定义)时,什么都没有绘制(出现一个空窗口)。
似乎调用 plt.close() 会影响 matplotlib 的所有行为(我尝试手动关闭窗口,脚本能够一个接一个地绘制不同的图形)
你遇到过这种问题吗?
非常感谢您的帮助
最好的
文森特
【问题讨论】:
标签: python matplotlib