我想在每个draw()
操作上绘制一个新图。我拼凑code来绘制一个静态图形,在创建对象后永不更新。但我希望能够在显示新数据时重绘。
如何构建代码以构建可重绘的数字?
以下是有问题的代码,它只绘制一次:
from numpy import arange, sin, pi
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
class CanvasPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
#self.size = (800, 50)
self.figure = Figure()
self.figure.set_size_inches( (8,1) )
self.figure.set_dpi(80)
#self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure )
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
def draw(self):
self.axes = self.figure.add_subplot(111)
t = arange(0.0, 3.0, 0.01)
s = sin(2 * pi * t)
self.axes.plot(t, s)
#time.sleep(5)
#self.figure.clear()
答案 0 :(得分:2)
正如@acattle在他的评论中所建议的,你需要做的就是在更新你的情节后将这些行添加到你的绘图子程序中:
self.canvas.draw()
self.canvas.Refresh()