0

matplotlib次の図の線に沿って、特定のアスペクト比、異なるスケールの 2 つの x 軸と 2 つの y 軸、および再フォーマットされた目盛りラベルを持つ図を生成しようとしています。

ここに画像の説明を入力

私はmatplotlib限ります

x_power_min = -2
x_power_max =  3
y_power_min = -5
y_power_max =  2
fig_ratio = 1.2

fig, axy = plt.subplots()

axy.set(xscale='log', xlim=[10**x_power_min,10**x_power_max], xlabel='X1')
axy.set(yscale='log', ylim=[10**y_power_min,10**y_power_max], ylabel='Y1')

axy.set_aspect(float(x_power_max-x_power_min) / float(y_power_max-y_power_min) * fig_ratio)

axy.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, pos: '{:0d}'.format(int(math.log10(x)))))
axy.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda y, pos: '{:0d}'.format(int(math.log10(y)))))

それは私に与えます

ここに画像の説明を入力

しかし、追加の軸を導入すると、エラーが発生します。そのため、次の行をValueError: math domain error - dL_width = math.log10(dL.x1) - math.log10(dL.x0)コメントアウトすることによってのみ続行できますset_aspect

fig, axy = plt.subplots()
ay2 = axy.twinx()
ax2 = axy.twiny()

axy.set(xscale='log', xlim=[10**x_power_min,10**x_power_max], xlabel='X1')
axy.set(yscale='log', ylim=[10**y_power_min,10**y_power_max], ylabel='Y1')
ay2.set(yscale='log', ylim=[317.83*10**y_power_min,317.83*10**y_power_max], ylabel='Y2')
ax2.set(xscale='log', xlim=[10**(3*x_power_min/2.0),10**(3*x_power_max/2.0)], xlabel='X2')

#axy.set_aspect(float(x_power_max-x_power_min) / float(y_power_max-y_power_min) * fig_ratio)

axy.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, pos: '{:0d}'.format(int(math.log10(x)))))
axy.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda y, pos: '{:0d}'.format(int(math.log10(y)))))
ay2.yaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda y, pos: '{:0d}'.format(int(math.log10(y)))))
ax2.xaxis.set_major_formatter(matplotlib.ticker.FuncFormatter(lambda x, pos: '{:0d}'.format(int(math.log10(x)))))

その結果、間違った縦横比のグラフが生成されます。

ここに画像の説明を入力

4

1 に答える 1