35

私はmatplotlibでいくつかのデータをプロットしています。プロットで特定の範囲の x 値に焦点を合わせたいので、set_xlim() を使用しています。

おおよそ、私のコードは次のようになります。

fig=plt.figure()
ax=fig.add_subplot(111)
for ydata in ydatalist:
    ax.plot(x_data,y_data[0],label=ydata[1])
ax.set_xlim(left=0.0,right=1000)
plt.savefig(filename)

プロットを見ると、x の範囲は 0 から 12000 になります。これは、set_xlim() が plot() の前または後に発生した場合に発生します。この状況で set_xlim() が機能しないのはなぜですか?

4

5 に答える 5

18

好奇心から、oldxminとの切り替えはどうxmaxですか?

fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(x_data,y_data)
ax.set_xlim(xmin=0.0, xmax=1000)
plt.savefig(filename)
于 2013-07-19T19:50:08.277 に答える
16

この回答のテキストは、投稿直後に削除された回答から取られました。

set_xlim()プロットに表示されるデータを制限します。

軸の境界を変更するには、 を使用しますset_xbound()

fig=plt.figure()
ax=fig.add_subplot(111)
ax.plot(x_data,y_data)
ax.set_xbound(lower=0.0, upper=1000)
plt.savefig(filename)
于 2013-07-19T05:02:25.983 に答える