I think the current method names of Annotation class (originally from
the Text class) is a bit confusing.
And this needs to be fixed.
Anyhow, instead of calling set_position method, you need to set the
"xytext" attribute directly.

        this_annotation.xytext = (event.x, event.y)

Regards,

-JJ


On Wed, Jan 6, 2010 at 9:49 AM,  <charles.rod...@gmail.com> wrote:
> Dear all,
>
> I have a little problem on understanding how to move an annotation on a
> plot.
>
> My idea is to make a plot where some informations follow the cursor when
> moving on the data, like you can see in plots from piwik (
> http://piwik.org/demo )
>
> In the script in attachment, I can follow the cursor coordinate, change the
> text of the annotation, but I cannot move it.
>
> I tried several things, but none worked.
>
> If you have any advices, I would be very happy.
>
> =============================
> Script : try_move_annotate.py
> =============================
> import numpy
> import matplotlib
> import matplotlib.pyplot as plt
>
> def on_motion(event):
> if event.inaxes:
> print "before setting position : "
> print this_annotation.get_position()
> this_annotation.set_text('coordinate : ' + str(event.x) + ' ' +
> str(event.y))
> this_annotation.set_position((event.x, event.y))
> print "after setting position : "
> print this_annotation.get_position()
> ax.draw_artist(this_annotation)
> plt.draw()
>
> fig = plt.figure()
> ax = fig.add_subplot(111)
>
> ax.plot(range(10), range(10))
> this_annotation = ax.annotate("coordinate : ",
> xy = (100,100),
> xycoords = 'figure pixels',
> horizontalalignment = 'left',
> verticalalignment = 'top',
> fontsize = 20,
> fontweight = 'bold',# animated=True,
> bbox = dict(boxstyle="round", fc='black', ec="0.5", alpha=0.5)
> )
>
> fig.canvas.mpl_connect('motion_notify_event', on_motion)
> plt.show()
> ==========
> END Script
> ==========
> ------------------------------------------------------------------------------
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and easy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to