|
From: Dominique O. <Dom...@po...> - 2004-12-23 16:44:18
|
John,
Many thanks for the lengthy and thorough explanations on transformations
in matplotlib. I am working my way through them and the source files. I
am still trying to get my line+triangle example to work; i think it
might be flexible in the end, if we want to, e.g., position the head
anywhere along the stem, or use different polygons for the head. Your
polygon example is certainly flexible for shaping the arrow, but for
instance, if i want to draw an 'oriented path' in 2d space, it will
become more complicated.
I can now position the stem correctly and the head 'almost' correctly
using offsets. Here is what i have in my Arrow class:
orig, dest = zip( xdata, ydata )
self._x = tuple( xdata )
self._y = tuple( ydata )
self._center = dest # Temporary
radius = 4
# Stem
self._stem = Line2D( self._x, self._y, **kwargs )
self._stem.set_transform( ax.transData )
# Head
self._head = RegularPolygon( tuple(self._center), 3,
radius = radius, orientation = angle, **kwargs )
trans = identity_affine()
trans.set_offset( tuple( dest ), ax.transData )
self._head.set_transform( trans )
and the draw() method just says:
def draw( self, renderer ):
# Draw stem and head
self._stem.draw( renderer )
self._head.draw( renderer )
You instantiate it, for example, with:
ax = axes( [0.1, 0.1, 0.8, 0.8], polar = polar )
ax.set_xlim( [0,10] )
ax.set_ylim( [0,10] )
arr = ax.arrow( [1, 4], [1, 5] )
to draw an arrow from (1,1) to (4,5).
There are two things:
1) I know the center of the arrow head isn't right; i'll shift it later
2) The arrow is drawn correctly (even on polar axes) but there is a
slight gap between the tip of the stem and the bottom of the head;
although the center should coincide with the tip (called 'dest' in the
code excerpt).
Why isn't the triangle centered where the tip of the stem is?
Dominique
|