-->

如何更新FigureCanvasTkAgg内容(How to update the contents

2019-06-27 09:24发布

我使用的Tkinter的FigureCanvasTkagg绘制一些数据matplotlib 。 我需要清除的身影,我绘制数据,并在按下按钮绘制新的数据。

这里是代码的一部分绘制(有之前定义的App类):

    self.fig = figure()
    self.ax = self.fig.add_subplot(111)
    self.ax.set_ylim( min(y), max(y) )      

    self.line, = self.ax.semilogx(x, y, '.-')   #tuple of a single element
    self.canvas = FigureCanvasTkAgg(self.fig, master=master)
    self.ax.semilogx(x, y, 'o-')
    self.canvas.show()
    self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
    self.frame.pack()   

如何更新这样的画布的内容是什么?

Answer 1:

#call the clear method on your axes
self.ax.clear()

#plot the new data
self.ax.set_ylim(min(newy), max(newy))
self.ax.semilogx(newx, newy, 'o-')

#call the draw method on your canvas
self.canvas.draw()

希望这可以帮助



文章来源: How to update the contents of a FigureCanvasTkAgg