I have noticed that when using Text.set_x
or Text.set_y
or Text.set_position()
on axis labels (e.g. gca().xaxis.label
), the labels are ignoring the dimension other than their main axis - i.e. when if xaxis.get_position()
returns (0.5, 325), if I run xaxis.set_position(0.25, 400)
, only the x component updates, giving a position of (0.25, 325).
I have prepared an illustrative plot:
Generated with the MWE below. As you can see, the labels only want to move in one direction. Apparently I can move them around with labelpad, but it seems weird to have the asymmetry and I'd be interested to know why it exists, and if there's another way I'm missing to set the axis positions to arbitrary coordinates?
The MWE code is below:
# Minimum working example demonstrating label failures
from numpy import *
from scipy import *
from matplotlib.pyplot import plot, subplot, title, figure
# Coosing an aribtrary function.
x = linspace(1, 5, 20); y = (1/x)*cos(x);
xl = []; yl = [] # Save the labels in an array
titles = ['Control', 'X Moved Along X, Y Moved Along X', 'X Moved along Y, Y moved Along Y', 'X Moved Along Y, Y Moved Along X']
figure(figsize=(10,10), dpi=60)
for i in range(0, 4):
subplot(2, 2, i+1)
plot(x, y, 'o--')
xl.append(xlabel('x (unitless)', fontweight='semibold', fontsize=14))
yl.append(ylabel('y (unitless)', fontweight='semibold', fontsize=14))
title(titles[i], fontsize=12)
xlim(1, 5)
# Only the x label moves
subplot(2, 2, 2)
xl1x = xl[1].get_position()[0]
yl1x = yl[1].get_position()[0]
xl[1].set_x(xl1x+0.2)
yl[1].set_x(yl1x+0.2)
# Only the y label moves
subplot(2, 2, 3)
xl2y = xl[2].get_position()[0]
yl2y = yl[2].get_position()[0]
xl[2].set_y(xl2y+0.2)
yl[2].set_y(yl2y+0.2)
# Neither moves
subplot(2, 2, 4)
xl3y = xl[3].get_position()[0]
yl3x = yl[3].get_position()[0]
xl[3].set_y(xl3y+0.2)
yl[3].set_x(yl3x+0.2)
tight_layout()
show()