如何更新 FigureCanvasTkAgg 的内容 [英] How to update the contents of a FigureCanvasTkAgg
本文介绍了如何更新 FigureCanvasTkAgg 的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 matplotlib
在 Tkinter FigureCanvasTkagg 中绘制一些数据.当按下按钮时,我需要清除绘制数据和绘制新数据的图形.
I'm plotting some data in a Tkinter FigureCanvasTkagg using matplotlib
.
I need to clear the figure where I plot data and draw new data when a button is pressed.
这是代码的绘图部分(之前定义了一个 App 类):
Here is the plotting part of the code (there's an App class defined before):
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()
如何更新此类画布的内容?
How do I update the contents of such a 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()
希望能帮到你
这篇关于如何更新 FigureCanvasTkAgg 的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文