How to update the contents of a FigureCanvasTkAgg

你。 提交于 2019-11-29 07:16:20

问题


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.

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?


回答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()

hope this helps



来源:https://stackoverflow.com/questions/12124350/how-to-update-the-contents-of-a-figurecanvastkagg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!