我正在使用matplotlib
在Tkinter FigureCanvasTkagg中绘制一些数据。
我需要清除我绘制数据的图形,并在按下按钮时绘制新数据。
以下是代码的绘图部分(之前定义了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()
如何更新此类画布的内容?
答案 0 :(得分:10)
#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()
希望这会有所帮助