|
From: John H. <jdh...@ac...> - 2005-01-31 20:01:53
|
>>>>> "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?
Dominique> Are the methods gca().transData.xy_tup() and
Dominique> inverse_xy_tup() what I'm looking for? If so, how
Dominique> should I be calling them?
I think the easiest way is to transform the data to screen coordinates
and then apply a scale factor to convert pixels to points. All of the
transform methods
xy_tup(xy) - transform the tuple (x,y)
seq_x_y(x, y) - transform the python sequences x and y
numerix_x_y(x, y) - x and y are numerix 1D arrays
seq_xy_tups(seq) - seq is a sequence of xy tuples
return screen coords. To get points from left, bottom, you would
could convert to inches by dividing by dpi, and then multiply by the
number of points per inch. Untested, off the cuff, but should be
right:
# 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
with the usual caveat that screen dpi is not the same in the x and y
directions so the physical units may not be exact when displayed.
JDH
|