Annotation add_artist bug

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))

ax.add_artist(text)

ax.add_artist(ann) #this does not work

ax.set_xlim(-1, 5)

ax.set_ylim(-1, 5)

show()

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()

···

On Aug 19, 2008, at 11:37 AM, Ben Axelrod wrote:

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

I've installed the Enthought Python Distribution for Mac OS on my MacOS 10.4 Intel machine.

when i try to install basemap-0.99.1 I get this error:

gcc: unrecognized option '-no-cpp-precomp'
cc1: error: unrecognized command line option "-mno-fused-madd"
cc1: error: unrecognized command line option "-arch"
cc1: error: unrecognized command line option "-Wno-long-double"
error: Command "gcc -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk -fno-strict-aliasing -Wno-long-double -no-cpp-precomp -mno-fused-madd -fno-common -dynamic -DNDEBUG -g -O3 -Isrc -I/Library/Frameworks/Python.framework/Versions/4.0.30001/lib/python2.5/site-packages/numpy-1.1.1.0001-py2.5-macosx-10.3-fat.egg/numpy/core/include -I/Library/Frameworks/Python.framework/Versions/4.0.30001/include/python2.5 -c src/PJ_gn_sinu.c -o build/temp.macosx-10.3-i386-2.5/src/PJ_gn_sinu.o" failed with exit status 1

Any ideas?

lisa tauxe