updating embedded plots using Tkinter

Hi Everyone,

I’m running into a problem with updating a plot that
I’ve embedded into a Tk application. I’m attaching the code with this email (so hopefully that will show up at the end of the email). This is
a very simple program, with one canvas embedded into a window, with one
menu and one button Tk widgets that I’m using to select what plot type to display. The data are x, y, and t variables, with x and y given by cos(2pit) and sin(2pit) respectively. I’d like to be able to switch
between a single scatter plot and two x(t) and y(t) plots. The program
“works” in that when you resize the window, the plot updates, however, this really isn’t ideal. I’d like the plot to refresh when the button is clicked, and I can’t seem to get it to work, nor could I find support
in previous email archives.

It seems like the trick used for animations, that is, only calling ‘plot’ once and simply changing the xdata and ydata values of the line would speed things up significantly, so I’ve implemented that in the code, but it doesn’t help.

Any help would be much appreciated! Thanks in advance.

Michael

embed_test.py (4.53 KB)

2011/4/22 Michael Schmidt <elmickerino@...287...>:

Hi Everyone,

I'm running into a problem with updating a plot that I've embedded into a Tk
application. [...] I'd like the plot to
refresh when the button is clicked

pyplot.draw() does not work here (I don't know if this is intended
behavoir of pyplot, but it makes some sense). Using canvas.draw()
fixes your program in my mpl setup.

Goyo

Great, thanks for the fix, works great now!

--Michael

···

On Fri, Apr 22, 2011 at 2:17 PM, Goyo <goyodiaz@...287...> wrote:

2011/4/22 Michael Schmidt <elmickerino@...287...>:

Hi Everyone,

I'm running into a problem with updating a plot that I've embedded into a Tk
application. [...] I'd like the plot to
refresh when the button is clicked

pyplot.draw() does not work here (I don't know if this is intended
behavoir of pyplot, but it makes some sense). Using canvas.draw()
fixes your program in my mpl setup.

Goyo