On Aug 19, 2008, at 11:37 AM, Ben Axelrod wrote:
When I try using axes.add_artist() to add an Annotation object, it
does not work. Adding a Text object in this manner works fine.
Shouldn’t Annotation also work since it inherits from Text? The
sample code below demonstrates. I am using version 0.98.3.
from matplotlib.pyplot import figure, show
from matplotlib.text import Text
from matplotlib.text import Annotation
fig = figure()
ax = fig.add_subplot(111)
text = Text(0, 0, 'This is Text')
ann = Annotation('This is an Annotation', (1, 1))
ax.annotate('This is another Annotation', (2, 2))
I looked at the annotate method in axes.py and the key difference is
that it sets the transform keyword arg to the IdentityTransform. In
otherwords, you can add something like this:
>>> import matplotlib.transforms as mtransforms
>>> ann = Annotation('This is an Annotation', (1, 1),
... transform=mtransforms.IdentityTransform())
Strangely, `ann.get_transform()` returns `IdentityTransform()` even if
you *don't specify the transform keyword*. I don't understand why this
(setting the transform kwarg) works, but it does change *final*
transform. In other words, if you check the artist transforms *after
adding the artists*, you'll notice when the transform is explicitly
set (as above), the transform remains the IdentityTransform; otherwise
it will be changed to the same transform as the Text instance.
I don't understand why the IdentityTransform would be the correct
transform for annotations or why Text and Annotation should have
different transforms. Maybe a developer could enlighten us.
Best,
-Tony
ax.add_artist(text)
ax.add_artist(ann) #this does not work
PS. To check the final transform, add the following code after adding
artists:
>>> for a in ax.artists:
... print a
... print a.get_transform()
ax.set_xlim(-1, 5)
ax.set_ylim(-1, 5)
show()
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's
challenge
Build the coolest Linux based applications with Moblin SDK & win
great prizes
Grand prize is a trip for two to an Open Source event anywhere in
the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/_______________________________________________
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 Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users