1

私は次のコードを持っていますが、それらを同じグラフに配置したいのですが、サブプロットは異なります。

異なる軸を作成する最も簡単な方法は何ですか?

from pylab import *

figure(0)
x =1
y = 2
plot(x, y, marker ='^', linewidth=4.0)
xlabel('time (s)')
ylabel('cost ($)')
title('cost vs. time')

figure(1)

x = 4
y = 100
plot(x, y, marker ='^', linewidth=4.0)
xlabel('cost ($)')
ylabel('performance (miles/hr) ')
title('cost vs. time')


show()
4

1 に答える 1

2

使用できますpyplot.subplotspyplotプログラミングに推奨されるAPIを使用しています(参照: http://matplotlib.sourceforge.net/api/pyplot_api.html#pyplot

import matplotlib.pyplot as plt

fig, (ax0, ax1) = plt.subplots(ncols=2)
x = 1
y = 2
ax0.plot(x, y, marker ='^')
ax0.set_xlabel('time (s)')
ax0.set_ylabel('cost ($)')
ax0.set_title('Plot 1')

x = 4
y = 100
ax1.plot(x, y, marker ='^')
ax1.set_xlabel('cost ($)')
ax1.set_ylabel('performance (miles/hr)')
ax1.set_title('Plot 2')

fig.suptitle('cost vs. time')
plt.subplots_adjust(top=0.85, bottom=0.1, wspace=0.25)
plt.show()

結果のプロット

于 2012-04-27T22:28:48.177 に答える