Hello all.
I'm trying to apply a transformation (Affine2D) to a text artist. For
some reason the artist doesn't show up in the plot. I have a simple
code here which demonstrates the problem. Any ideas what I'm doing
wrong?
Thanks
Jack Liddle
from numpy import *
import matplotlib.pyplot as plt
from matplotlib.text import Text
fig = plt.figure()
from matplotlib.transforms import Affine2D,Transform
ax1 = fig.add_subplot(111)
#Something to plot
xs = linspace(0,1,100)
ys = xs**2
ax1.plot(xs,ys)
#The transformation
mytrans = Affine2D()
print mytrans
print isinstance(mytrans,Transform)
t = Text(0.5,0.5,"Problems?",transform=mytrans)
ax1.add_artist(t)
plt.show()
The transformation must take input in your coordinate system and
output in display coordinate systems. The default Affine2D
transformation is identity, so you are transforming 0.5, 0.5 userland
coordinates to 0.5, 0.5 display. This display coordinate falls
outside the Axes window and so is being clipped. If you turn clipping
off, you will see part of your text in the lower left
t = Text(0.5, 0.5,"Problems?",transform=mytrans, clip_on=False)
If you want to see it in the middle of your plot, you could do something like
t = Text(200, 200,"Problems?",transform=mytrans, clip_on=False)
Note this transformation applies only to the x,y location of the text,
and will not transform the glyphs of the text.
See http://matplotlib.sourceforge.net/users/transforms_tutorial.html
for more details on transformations.
JDH
ยทยทยท
On Fri, Jun 11, 2010 at 9:38 AM, Jack Liddle <j.liddle@...3157...> wrote:
Hello all.
I'm trying to apply a transformation (Affine2D) to a text artist. For
some reason the artist doesn't show up in the plot. I have a simple
code here which demonstrates the problem. Any ideas what I'm doing
wrong?
Thanks
Jack Liddle
from numpy import *
import matplotlib.pyplot as plt
from matplotlib.text import Text
fig = plt.figure()
from matplotlib.transforms import Affine2D,Transform
ax1 = fig.add_subplot(111)
#Something to plot
xs = linspace(0,1,100)
ys = xs**2
ax1.plot(xs,ys)
#The transformation
mytrans = Affine2D()
print mytrans
print isinstance(mytrans,Transform)
t = Text(0.5,0.5,"Problems?",transform=mytrans)
ax1.add_artist(t)
plt.show()