From: John H. <jdh...@ac...> - 2005-09-12 20:29:17
|
>>>>> "N" == N Volbers <mit...@we...> writes: N> Hello list, I have just figured out how to use transformations N> for the 'Text' object from the class library to add a text to N> the graph (well actually this applies to any Artist object). N> If the coordinates are given as absolute _screen_ coordinates N> (very unlikely...), we use: N> t = Text(x=x, y=y, text=text) N> axes.texts.append(t) N> If however the coordinates are given as _data_ coordinates x,y N> then we use: N> t = Text(x=x, y=y, text=text) N> t.set_transform(axes.transData) N> ax.texts.append(t) You can also pass the transform as a kwarg t = Text(x=x, y=y, text=text, transform=axes.transData) ax.texts.append(t) N> My question: Is there any transformation that would allow me to N> specify the coordinates as x,y tuple where (0,0) is bottom left N> and (1,1) is top right? In gnuplot this is known as the 'graph' N> coordinate system. There are four built-in transforms that you should be aware of; below ax is an Axes instance and fig is a Figure instance matplotlib.transforms.identity_transform() # display coords ax.transData # data coords ax.transAxes # 0,0 is bottom,left of axes and 1,1 is top,right fig.transFigure # 0,0 is bottom,left of figure and 1,1 is top,right There is nothing wrong with instantiating Text instances yourself and adding them to the figure or axes manually as you did, but both the Axes and Figure have helper methods "text" which define a default transformation that can be overridden So t = Text(x=x, y=y, text=text) t.set_transform(axes.transAxes) ax.texts.append(t) is equivalent to ax.text(x, y, text, transform=ax.transAxes) The default transform for ax.text is ax.transData and the default transform for fig.text is fig.transFigure. Of course, you can define more general transformations, eg matplotlib.transforms.Affine, but the four listed above arise in a lot of applications. If you have time and inclination to write a transformations tutorial for the wiki, that would be great. Thanks, JDH |