draw()
我想在每个操作上绘制一个新图形。我拼凑了用于绘制静态图形的代码,该图形在创建对象后永远不会更新。但我希望能够在呈现新数据时重绘。
我如何构建我的代码来做可重绘的数字?
这是有问题的代码,它只绘制一次:
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()