from collections import LineCollection
class Arrow(LineCollection):
    """
    An arrow
    """
def __init__( self, x, y, dx, dy, width=1.0, arrowstyle='solid', **kwargs ):
        """Draws an arrow, starting at (x,y), direction and length
        given by (dx,dy) the width of the arrow is scaled by width.
        arrowstyle may be 'solid' or 'barbed'
        """
        L = math.hypot(dx,dy) or 1 # account for div by zero
        S = 0.1
        arrow = {'barbed': array([[0.,0.], [L,0.], [L-S,S/3],
                                  [L,0.], [L,-S/3], [L,0.]]),
                 'solid': array([[0.,0.], [L-S,0.], [L-S,S/3],
                                  [L,0.], [L-S,-S/3], [L-S,0.]])
                }[arrowstyle]

        cx = float(dx)/L
        sx = float(dy)/L
        M = array([[cx, sx], [-sx, cx]])
        verts = matrixmultiply(arrow, M) + [x,y]
LineCollection.__init__(self, [tuple(t) for t in verts], **kwargs)
I've found one problem with your Arrow LineCollection; it's not actually a line collection. It's one line, so some of the LineCollection functions fail on it. You need to break up the arrow into segments, like this:

'barbed': array([ [ [0.,0.], [L,0.] ],
                         [ [L,0.], [L-S,S/3] ],
                         [ [L,0.], [L-S,-S/3] ] ]

Except just doing this will break the matrixmultiply.  Just a heads-up.

Jordan


-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to