1

Text.set_xまたはを軸ラベル (例: ) で使用Text.set_yすると、ラベルが主軸以外の次元を無視していることに気付きました。 (0.25、325)の。Text.set_position()gca().xaxis.labelxaxis.get_position()xaxis.set_position(0.25, 400)

説明用のプロットを用意しました: X軸の動き

以下の MWE で生成されます。ご覧のとおり、ラベルは一方向にのみ移動します。どうやらlabelpadでそれらを移動できるようですが、非対称性があるのは奇妙に思えます。なぜそれが存在するのか知りたいのですが、軸位置を任意の座標に設定する方法が他にない場合は?

MWE コードは次のとおりです。

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

0 に答える 0