Hi,

I have some performance problems when plotting several lines and would
appreciate some comments. My application plots lots of lines (~5000)
of different sizes. The performance bottleneck lies in the following
code snippet:

for s in data.layout.segment:
    x = []
    y = []
    for p in s.part:
        for px, py in p.curve_points():
            x.append(px)
            y.append(py)
    axes.plot(x, y, 'g', label = '_nolegend_')

Profiling showed that half of the time was spent in parsing the plot
arguments and most of the other half was spent in
Axes._set_artist_props.

I could speed up the application by using Line2D and
Axes.add_lines. But the only way to come around the time spent in
Axes._set_artist_props that I could come up with is this ugly hack
where I only call Axes.add_line for the first line and after that use
copies that are added directly to Axes.lines.

org_line = None
for s in data.layout.segment:
    x = []
    y = []
    for p in s.part:
        for px, py in p.curve_points():
            x.append(px)
            y.append(py)
    if not org_line:
        org_line = matplotlib.lines.Line2D(numpy.array(x), numpy.array(y),
                                           color='green', label = '_nolegend_')
        axis.add_line(org_line)
    else:
        line = copy.copy(org_line)
        line.set_xdata(numpy.array(x))
        line.set_ydata(numpy.array(y))
        axis.lines.append(line)

Is there a cleaner way to do this?

Also, my feelings is that matplotlib 1.0 is slower with my original
code than previous version. But I have no numbers to back it up with.

regards
Ulf Larsson
                                          
------------------------------------------------------------------------------
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to