Ah. I wasn't quite clear on what you were trying to do before.
There's actually a bit of "magic" in there that automatically adjusts the xlabel so it is lower than the xtick values. (If you rotate the xtick values, you can see this in action). So it actually does position things how you want, but then when it goes to draw it is automatically lowering the text a little to make room.
Since I don't see an easy way around this magic, you could not use xlabel at all and just add some Axes text:
from matplotlib import text
text = text.Text(1, 0, "Foo")
text.set_transform(offset_copy(axes.transAxes, axes.figure, x=5, y=0, units='points'))
text.set_clip_on(False)
axes.add_artist(text)
Completely non-obvious of course If there's enough need for the kind of xlabels you're making, we should probably provide a way to do this directly, but it would have to be well-tested to ensure it didn't break existing functionality.
Mike
···
jason-sage@...2130... wrote:
Michael Droettboom wrote:
The xlabel doesn't use the data transform, it uses the axes transform, where the edges of the axes always go from 0.0 to 1.0, regardless of the data extents. Therefore, tou can start with the label's default transform:
trans = xlabel.get_transform()
and use that as the basis for the offset transform
offtrans = offset_copy(trans, subplot.figure, x=5, y=0, units='points')
and set the label's position, alignment and transform:
xlabel.set_position((1, 0))
xlabel.set_ha('right')
xlabel.set_transform(offtrans)Hope that does what you're after.
Thanks! This helps a lot.
I notice with the following, the x-axis label is lined up with its baseline equal to the baseline of the tick labels. I'd like the baseline to be the same as the actual axis line. What should I do to get the baseline of the x-axis label to be the actual axis line? I've been working on this for a while tonight, and I've made a lot of progress, but now I'm getting confused. Is there some sort of padding going on, even though I set labelpad=0? Is the problem I'm seeing because I started from xlabel.get_transform(), which already has the padding builtin?from matplotlib.transforms import offset_copy
subplot.xaxis.labelpad=0
xlabel=subplot.xaxis.get_label()
trans=xlabel.get_transform()
xlabel.set_horizontalalignment('left')
xlabel.set_verticalalignment('baseline')
xlabel.set_transform(offset_copy(trans,subplot.figure,x=5,y=0,units='points'))xlabel.set_position((1,0))
Thanks,
Jason
--
Jason Grout
--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA