[Solved] How to update the contents of a 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.

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.get_tk_widget().pack(side='top', fill='both', expand=1)

How do I update the contents of such a canvas?

Enquirer: Copo

Solution #1:
#call the clear method on your axes

#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

hope this helps

Respondent: Oblivion
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Leave a Reply

Your email address will not be published.