Michael Droettboom wrote:
so are you working on an example? Or should I?
I'm happy to do it, but may not get to it for a few days. My own test was to run "simple_plot_fps.py" with "handle_clip_rectangle" (in backend_wx.py) turned on and off. But obviously the wxPython folks will want a more standalone example.

I've made a standalone example (enclosed). It simply makes a call to

GraphicsContext.DrawLines()

with and without clipping. In this case, it's actually a bit faster clipped (on OS-X). Maybe it's different with Paths -- I haven't dug into the MPL code to see how it's being used there.

Also, the whole thing almost hangs (134 seconds to draw) if I up the number of points to 5000!

Could you alter this to use the drawing calls MPL is actually using, then we can send it on the wxPython list.

-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

[EMAIL PROTECTED]
#!/usr/bin/env python

"""
A simple file for testing GraphicsContext speed -- at least for clipping a polyline
"""

import wx
import time
import numpy as np

class TestPanel(wx.Panel):
    def __init__(self, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        
        N = 1000
        self.Data = np.zeros((N,2))
        self.Data[:,0] = np.linspace(0, 1.0, N)
        self.Data[:,1] = np.random.uniform(0, 1.0,  (N,))
        
        self._buffer = None
        self.Clip = False
        
        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnSize(self, evt):
        x,y = self.GetSize()
        self._buffer = wx.EmptyBitmap(x,y)
        self.Draw()

    def OnPaint(self, evt):
        dc = wx.PaintDC(self)
        dc.DrawBitmap(self._buffer, 0, 0)
        
    def Draw(self, evt=None):
        dc = wx.MemoryDC()
        dc.SelectObject(self._buffer)
       
        X, Y = self._buffer.GetSize()
       
        box = (0.1*X, 0.1*Y, 0.8*X, 0.8*Y)
        # scale the data to fit the Window
        data = self.Data * (X,Y)
        ctx = wx.GraphicsContext_Create(dc)
        
        # Note: is the only way to clear the bitmap??
        ctx.SetBrush(wx.WHITE_BRUSH)
        ctx.DrawRectangle(0, 0, X, Y)
        ctx.SetBrush(wx.TRANSPARENT_BRUSH)
        
        ctx.SetPen(wx.BLACK_PEN)
        ctx.DrawRectangle(*box)

        if self.Clip:# clip the drawing:
            print "Clipping the Drawing: ",
            ctx.Clip(*box)
        else:
            print "Not clipping the Drawing: ",
        ctx.SetPen(wx.Pen("red", 2))
        start = time.clock()
        ctx.DrawLines(data)
        end = time.clock()
        self.DrawTime = end-start
        print "Drawing Took: %s seconds"%self.DrawTime
        self.Refresh()
        
class TestFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
    
        self.Panel = TestPanel(self)
        
        self.button = wx.Button(self, label="Clip")
        self.button.Bind(wx.EVT_BUTTON, self.OnClick)

        S = wx.BoxSizer(wx.VERTICAL)
        S.Add(self.Panel, 1, wx.EXPAND)
        S.Add(self.button, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5)
        
        self.SetSizer(S)

    def OnClick(self, event):
        label = self.button.GetLabel()
        if label == "Clip":
            self.button.Label = "Don't Clip"
            self.Panel.Clip = True
        elif label == "Don't Clip":
            self.button.Label = "Clip"
            self.Panel.Clip = False
        self.Panel.Draw()
        self.Layout()

if __name__ == '__main__':
    app = wx.App(False)
    f = TestFrame(None)
    f.Show()
    app.MainLoop()
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to