On Tue, Jul 28, 2009 at 9:11 AM, Roland Koebler<r.koeb...@yahoo.de> wrote: > Hi, > > I've got some performance problems with matplotlib, and would like to > ask if you know any way I can make it faster. > > If there is no such way, I have to decide to (a) either enhance matplotlib > or (b) write my own plotting-library. > (I'm currently using matplotlib to plot data "live" on the screen, including > animation, scrolling, zoom+pam, custom scales (to zoom out some part of the > plot), and multiple X-/Y-Axes. I therefore already wrote some wrappers around > matplotlib to implement some of these features.) > > In detail: > - I have a figure containing some plots (lines). > - About every second I "update" the plot: > - Add a few points to the lines. > (=add point to an array and call set_data(array)) > - Scroll the plot, so that the latest point is on the right of the plot. > Older points disappear on the left side of the plot. > (=set_xaxis() + draw()) > - I'm using GtkAgg, incl. animation, (re)storing the background, drawing > the artists and blit. > (canvas.restore_region(...), ax.draw_artist(...), canvas.blit(bbox)) > > This works as long as the plot only contains a few points, > although 2 figures + 5-10 lines per figure and an update every 0.5 s > already consumes about 10-20% CPU (on a 1.4 GHz Pentium). > By the way: Is this speed normal, or is matplotlib usually faster? > > But as soon as the plot contains *many* points (several 10000 up to > several 100000), the plotting becomes terribly slow -- up to 30s > per update and more! > > Do you know any way to make this faster? > > My ideas are: > - Since I only add points to the *right* of the lines, I could reduce the > number of points, by first removing all points which are outside of > the current visible plotting-window from my array, and then calling > set_data() with the reduced array. > - This unfortunately wouldn't reduce the number of points in very dense > plots. It would be possible to (a) replace several points which all > result in the same plotted point by a single point or (b) cache the > plotted points e.g. on pixel-level. I think (b) would probably require > to write a new backend. > > Any ideas? >
http://matplotlib.sourceforge.net/examples/animation/animation_blit_gtk2.html The above example does something similar to (b). It saves the previous plot (only axes area is saved) as a bitmap. In next run, it restores the saved bitmap after shifting. And then draw only the new data points. The example requires the svn version of matplotlib. Regards, -JJ > > regards, > Roland > > > ------------------------------------------------------------------------------ > Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day > trial. Simplify your report design, integration and deployment - and focus on > what you do best, core application coding. Discover what's new with > Crystal Reports now. http://p.sf.net/sfu/bobj-july > _______________________________________________ > Matplotlib-users mailing list > Matplotlib-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users