[Matplotlib-users] Animated plots in a Tkinter application
Hi, Could anyone give a working example of an embedded, animated plot in a Tkinter application, where animated=True is used together with canvas background copying to make efficient animated plots in Tkinter together with other widgets? I cannot make it work myself, see below. I am working on a prototype, where have some Tkinter widgets to control what is plotted. What I want to plot is something which progress in time depending on the state of the widgets, and it is potentially a lot of graphs and details on the canvas, but only minor changes between updates. So I would rather avoid redrawing the whole canvas. I would therefore like to use the trick with copying the backgorund, static canvas from frame to frame to a buffer, and only draw the animated artists on top of it as is discussed in http://www.scipy.org/Cookbook/Matplotlib/Animations#head-3d51654b8306b1585664e7fe060a60fc76e5aa08 and also examplified in http://matplotlib.sourceforge.net/examples/animation/animation_blit_tk.html Now, the example does not embed the matplotlib canvas in a Tkinter root class, which I need if I want to add other Tk widgets on the same window I have therefore tried to modify the animation by merging in the embbedding in Tk example: http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.html The closest I have gotten to something, which works is this: import matplotlib matplotlib.use('TkAgg') import Tkinter import sys import pylab as p import numpy as npy import time root = Tkinter.Tk() fig = matplotlib.figure.Figure() ax = fig.add_subplot(111) canvas = matplotlib.backends.backend_tkagg.FigureCanvasTkAgg(fig, root) canvas.get_tk_widget().grid() # create the initial line x = npy.arange(0,2*npy.pi,0.01) ax.grid(True) # canvas.show() #If I add this, it does not show anything? line, = ax.plot(x, npy.sin(x), animated=True, lw=2) def run(*args): background = canvas.copy_from_bbox(ax.bbox) # for profiling tstart = time.time() while 1: # restore the clean slate background canvas.restore_region(background) # update the data line.set_ydata(npy.sin(x+run.cnt/10.0)) # just draw the animated artist ax.draw_artist(line) # just redraw the axes rectangle canvas.blit(ax.bbox) if run.cnt==1000: # print the timing info and quit print 'FPS:' , 1000/(time.time()-tstart) sys.exit() run.cnt += 1 run.cnt = 0 manager = p.get_current_fig_manager() manager.window.after(100, run) p.show() # If I outcomment this, the graph does not animate Now, this does show an efficient animated plot embedded in a Tk application, but I cannot make it work witout instatiating the other annoying backgroud window, whcih pops up when the p.show() is done. However, if i uncomment it, I never get a visible window. As I have understood the cookbook, one should draw the canvas before copying it to the background and before drawing the animated Artists. However, if I do that it does not work either. I must admit, that I do not fully grasp waht is goin on in the lines, where the current figure manager is associated woth the run method. Another problem with the naimation is that it is not possible to close it nicely. Any help would be appreciated. Kim -- ___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] py2exe problems for a tkinter/matpotlib project - works for me, but not for others
Hi group, I have previously had success with py2exe and matplotlib, using a specialized setup.py like the attached one (which is adapted from http://www.py2exe.org/index.cgi/MatPlotLib). However, now I have tried to go a step further and integrate some Tkinter controls in the GUI for a prototype, see attached alphabeta.py If I do a python setup.exe py2exe with this setup file on the attached Tkinter/matplotlib and alphabeta.exe is successfully created. However, it does not run for everyone else: Myself: Works like a charm A user with a python environment who make py2exes himself: Crashes on startup with the attached error log A user with just a Python environment: Works! A user with no Python environment: Crashes on startup with the same log. The log does not give me any good ideas as to how I could modify setup.py to get it working. Any good ideas? Some details about my environment when running py2exe OS. Win XP SP3 Python: 2.5.2 Numpy: 1.3.0 SciPy: 0.7.1 matplotlib: 0.99.1 py2exe: 0.6.9 Additional notice: A few days ago I asked for help getting hole through to a matplotlib/Tkinter application. I was not subscribed to this list then and could not reply on the answers. But the answers were useful, thanks! In addition, one respondend asked if I knew how to update a graph without having to clear the canvas and do everything all over? Well, I did not know the answer at that time, but the alphabeta.py example actually does it in a cooler way, which updates the data in the Line2D instance, which is returned when calling subplot.plot(...) That basic approach is also described quite well here: http://www.scipy.org/Cookbook/Matplotlib/Animations Maybe the alphabeta.py could be added to the examples for Tkinter integration as a slightly more advanced example of Tkinter integration? alphabeta.py Description: Binary data setup.py Description: Binary data alphabeta.exe.log Description: Binary data -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users
[Matplotlib-users] How do I use a grid geometry manager in a matplotlib tk backend
Hi matplotlib list, I am a resonably experienced python and matplotlib user, when it comes to make cmd line programs for batch processing, but I have never tried to make python GUI before. I am working on a prototype product, where I want the typical matplotlib plotting window, but extended with controls, such that I can control certain parameters determining what is being plotted. I have looked at the embedding_in_tk.py example http://matplotlib.sourceforge.net/examples/user_interfaces/embedding_in_tk.html which uses the pack manager. That example works like a charm for me, and it seems like i should be able to extend it for my needs I have also managed to add controls to that using the Tkinter module and pack(), i.e., the tedious to maintain pack manager However, I would really like to use a grid geometry manager instead as I find it much easier to manage. I have therefore tried to modify the example to use grid instead by moifying the two pack lines in the example ... #canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) canvas.get_tk_widget().grid(row=0) ... #canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) canvas._tkcanvas.grid(row=1) ... However, when I try to run that code, I just get an empty form I have tried other options in the grid method, with no success. I am sure i must be missing something obvious? Admittedly, these backend things are close to voodoo for me, so i am just trying to get a prrof of concepts, but i would not claim that i really undertsnad what is going on. I have tried to look for useful documentation for doing these kinds of things, but I have had only limited success. Directions/links to relevant material would be appreciated as well. Thanks, Kim -- Download Intel#174; Parallel Studio Eval Try the new software tools for yourself. Speed compiling, find bugs proactively, and fine-tune applications for parallel performance. See why Intel Parallel Studio got high marks during beta. http://p.sf.net/sfu/intel-sw-dev___ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users