John Hunter wrote:
>>>>>>"Dominique" == Dominique Orban <Dom...@po...> writes:
>
> Dominique> Regarding the use of transforms in Matplotlib, what
> Dominique> would be the simplest way to convert a quantity
> Dominique> expressed in data coordinates to points and conversely?
>
> # display coords
> dx, dy = trans.xy_tup(x, y)
>
> # points from left of figure window
> px = dx/dpi*72
>
> # points from bottom of figure window
> py = dy/dpi*72
Thanks, I think I understand. The reason I ask is to be able to compute
displacements in data coordinates when they are given in points.
Now I am confused by the following test (Windows XP, Matplotlib 0.71,
Numeric 23.0 from the Enthought edition of Python 2.3):
##################
from matplotlib.pylab import *
from matplotlib import rcParams
dpi = rcParams['figure.dpi']
ppi = 72.0
ratio = ppi/dpi
ax = axes( [0.1, 0.1, 0.8, 0.8] )
trans = ax.transData
z = (0,0)
dz = trans.xy_tup( z )
ddz = ( dz[0]*ratio, dz[1]*ratio )
print str(z) + ' in data units is ' + str(ddz) + ' in screen coords'
# See how many data units in each direction is a
# displacement of 'delta' points in each direction
delta = 5
r = ( ddz[0] + delta, ddz[1] + delta) # = origin + (10, 10)
rdx, rdy = trans.inverse_xy_tup( r )
rddx = rdx/ratio
rddy = rdy/ratio
print str(r) + ' in screen coords is ' + str((rddx,rddy)) + ' in data
units'
##################
This script produces:
(0, 0) in data units is (57.600000000000001, 43.200000000000003) in
screen coords
(62.600000000000001, 48.200000000000003) in screen coords is
(-0.0030381944444444415, 0.00057870370370370161) in data units
How is it possible that I obtain a negative number in this last tuple?
Is it a numerical error or am I missing something?
A second question: I want to draw a line going from (0,0) to (1,1), but
that stops short of (1,1), leaving just enough room for an object that
has a radius of 5 points. Is this how I should compute how far from
(1,1) the line should stop, in data coordinates?
Yes, this is related to the arrow class I mentioned in an earlier post.
This is an attempt to adjust the position of the arrow head, so its tip
points to, e.g., (1,1) and the stem is just long enough that it doesn't
overlap with the head. I'm probably not choosing the easy way but then,
I am not sure what the easy way would be.
Many thanks,
Dominique
|