python - 如何更新 FigureCanvasTkAgg 的内容

标签 python tkinter updating tkinter-canvas

我正在使用 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/

相关文章:

python - Google Drive API 的刷新 token 何时到期?

python - 如何将事件绑定(bind)到按住的鼠标左键?

python - Tkinter 消息框在按下“确定/确认”后不会消失

python - 简单的 sqlalchemy 过滤器不起作用

python - 距离小于 4cm 时的伽利略和超声波误差

python - 您可以使用 Python 从命令行完全验证 Facebook Graph 吗?

python - 是否有用于上传整个目录(包括子目录)的 python ftp 库?

python - 无法识别 PPM 文件数据

jquery - 使用 AJAX 动态更新表行

python - 终端中带有 block 字符的文本进度条