[wxPython-users] Draw method in PlotCanvas class for a number of points (>80,000) takes too much time

Christopher Barker Chris.Barker at noaa.gov
Mon Dec 11 16:49:12 PST 2006


jmf wrote:
> Two points here.
> 
> 1) My FloatCanvas experience is quite small. I was surprised maser rati 
> experimented so long drawing times, there is maybe a point here. I do
> not know.
> 
> 2) I'm quite happy with my plot functions. No, I do not use any
> markers, the time consuming part is the scaling ob, not the drawing
> process itsself which is achieved with a <dc>.DrawLineList().

That was directed at the OP, who has experienced VERY long draw time 
with PlotCanvas. I spent some time optimizing PlotCanvas a couple years 
ago, but haven't used it since.

As for your (jmf) code: numpy could speed it up a lot -- I use numpy for 
FloatCanvas for just that reason. But I'm sure you have your reasons for 
not using it.

> For info, the code of my plot routine.

I couldn't quite follow that, maybe I'd do better if I kept studying 
French after I was 14. However, numpy makes this sort of thing easy:

Here is the critical code for drawing a polyline in FloatCanvas:

     def _Draw(self, dc , WorldToPixel):
         Points = WorldToPixel(self.Points)
         dc.SetPen(self.Pen)
         dc.DrawLines(Points)

where WorldToPixel is a function that looks like:

def WorldToPixel(self,Coordinates):
         """
         This function will get passed to the drawing functions of the
         objects, to transform from world to pixel coordinates.

         Coordinates should be a NX2 array of (x,y) coordinates, or
         a 2-tuple, or sequence of 2-tuples.
         """
         #Note: this can be called by users code for various reasons,
         #      so N.asarray is needed.
         return  (((N.asarray(Coordinates,N.float_) -
                    self.ViewPortCenter)*self.TransformVector)+
                  (self.HalfPanelSize)).astype('i')


If that makes any sense!

All the multiplication and addition required to transform from world to 
pixel coords happens in a C loop, so it's fast.

-Chris


-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov




More information about the wxpython-users mailing list