From: John H. <jdh...@ac...> - 2004-11-06 22:40:43
|
>>>>> "Chris" == Chris <Ch...@Fu...> writes: Chris> Dear friends, I just start to use matplotlib, which looks Chris> quite promising for me. I need to draw a couple of arrows Chris> in my 2D plot. Is there a simple way to get it work? Chris> Any suggustions are welcome. I recommend creating an arrow class, derived from matplotlib.artist.Artist, that contains a matplotlib.lines.Line2D for the arrow stem and a matplotlib.patches.RegularPolygon with numVertices=3 for the arrow head. You can control the rotation of the arrowhead with the orientation argument. Once you have this class so defined, you can add it instances of it to the axes with ax.add_artist(arrow). I'll be happy to help out with a prototype if you have trouble. Take a look at matplotlib.table.Cell, which John Gill wrote to support tables. You can use this as a simple model for how to write new artists (things that draw into a figure) composed of other artists. It would be nice to have a fancy arrow class, that supported text labeling, at the base, along the stem and at the arrowhead. You could also consider a more sophisticated polygon other than a triangle for the arrowhead. Finally, if you needed to draw *a lot of arrows*, order of a thousand or more (eg for direction fields), a matplotlib.collections.PolygonCollection would be the way to go for efficiency. JDH |