matplotlib legend problem
John Hunter
jdhunter at ace.bsd.uchicago.edu
Fri Jan 27 11:56:24 EST 2006
>>>>> "bwaha" == bwaha <cfriedl at bigpond.net.au> writes:
bwaha> added the location argument. Finally realised it was due to
bwaha> having a default of 'best' location in my code which meant
bwaha> it went searching for intersection with lines that don't
bwaha> exist (outside of the LineCollection). So I disabled the
bwaha> 'best' location option. Then I figured, since I'd cleaned
bwaha> up my code a bit, I'd reinstate my earlier pylab.plot based
bwaha> line drawing code to see if the clean up made any
bwaha> difference to what was previously abysmal performance. The
bwaha> lines plotted faster than the LineCollection code! When I
bwaha> removed the legend hack for LineCollections there was
bwaha> virtually no difference. (Story is not finshed yet). So I
bwaha> figured after all that that I'd reinstate my pylab.plot
bwaha> based code since I could plot a greater range of symbols
bwaha> than with LineCollections with no speed loss. And I thought
bwaha> why not go the whole hog and reinstate the 'best' location
bwaha> option too. Boom! Plotting performance was abysmal
bwaha> again. Finally I realised that enabling 'best' and having
bwaha> it as the default meant that as I added new data to plot,
bwaha> the search time for a good place to put the legend
bwaha> increased dramtically, and probably became more difficult
bwaha> with more and more lines filling the canvas.
bwaha> Anyway now I'm a lot happier than when I started because
bwaha> I've retained my original range of plot styles and I got
bwaha> much faster plotting. Hopefully this lesson can help
bwaha> someone else.
Sorry you had to find this out after so much trial and error. For a
small number of large length lines (eg 10 at 30k points each), plot
will be much faster than line collections as you observed. For a
large number of small lines (eg 1000 at 20 points each) line
collections will be much faster. And yes, the "best" optimization for
the legend is slow -- I'm on the fence as to whether this should be
the default or not. At least clearly flagging this as a performance
bottleneck in the docs would be useful.
Cheers,
JDH
More information about the Python-list
mailing list