我正在使用 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()
如何更新此类 Canvas 的内容?
最佳答案
#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()
希望对你有帮助
关于python - 如何更新 FigureCanvasTkAgg 的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12124350/