Attached is a simple example that illustrates the method. What threw me off last night is that the copy_bbox_transform() function was not doing what I expected. I don't know yet whether this is because of a bug or a misunderstanding on my part, but in any case, the example provides an alternative. (It is not valid for any bbox transform, but I think it will be fine in normal use cases.) The basic method can be used on any artist by calling set_offset on that artist's transform. Once again, John's transform module works its magic!

I will make a more complete example and include it in the examples subdirectory of mpl. This is really great functionality that needs to be made more readily accessible.

Eric

John Hunter wrote:
"Eric" == Eric Firing <[EMAIL PROTECTED]> writes:


    Eric> I think that what you want to do requires something like the
    Eric> mechanism in QuiverKey: a derived artist with a draw method
    Eric> that figures out at draw time where to put the text; I don't
    Eric> think there is any other way to handle zooming while keeping
    Eric> the screen separation from a data point fixed.

You can do this using offsets -- see
matplotlib.axis.XTick._get_text1.  This is how tick labeling is done
(a point offset from an x location in data coords and a y location in
axis coords).  Here is an example -- you have to copy the default data
transform so that the offset doesn't affect the figure data

from matplotlib.transforms import Value, 
translation_transform,blend_xy_sep_transform
from pylab import figure, show

fig = figure()
ax = fig.add_subplot(111)
points = 7
pad = fig.dpi*Value(points/72.0)
# poor man's copy
trans = blend_xy_sep_transform(ax.transData, ax.transData)

# to the left and above
offset = translation_transform(Value(-1)*pad, pad)
trans.set_offset( (0,0), offset)

ax.plot([1,2,3])

t = ax.text(1,2, 'hi', transform=trans)

show()




import pylab as P
from matplotlib.transforms import translation_transform, copy_bbox_transform
from matplotlib.transforms import Value, identity_transform, get_bbox_transform

x = P.arange(5)
y = P.rand(5)

ax = P.subplot(1,1,1)

# copy_bbox_transform does not seem to work
#trans = copy_bbox_transform(ax.transData)

# Effectively doing a manual copy does work:
trans = get_bbox_transform(ax.transData.get_bbox1(),
                           ax.transData.get_bbox2())

transOffset = translation_transform(Value(10), Value(0))   # Alternative 1
transIdent = identity_transform()                          # Alternative 2

#trans.set_offset((0, 0), transOffset )   # Alternative 1
trans.set_offset((10,0), transIdent)      # Alternative 2


for x, y in zip(x,y):
    P.plot((x,),(y,), 'ro')
    P.text(x, y, '%0.3f' % y, transform=trans)

P.show()

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to