Matplotlib-twin-axes

提供:Dev Guides
移動先:案内検索

Matplotlib-ツイン軸

図に2つのx軸またはy軸があると便利です。 さらに、異なる単位の曲線を一緒にプロットする場合。 Matplotlibは、twixand関数でこれをサポートしています。

次の例では、プロットには2つのy軸があり、1つはexp(x)を示し、もう1つはlog(x)を示します-

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
a1 = fig.add_axes([0,0,1,1])
x = np.arange(1,11)
a1.plot(x,np.exp(x))
a1.set_ylabel('exp')
a2 = a1.twinx()
a2.plot(x, np.log(x),'ro-')
a2.set_ylabel('log')
fig.legend(labels = ('exp','log'),loc='upper left')
plt.show()

ツイン軸