2013-07-18 109 views
12

我正在用matplotlib繪製一些數據。我想讓情節專注於特定範圍的x值,所以我使用set_xlim()。爲什麼set_xlim()沒有在我的圖中設置x限制?

粗略地說,我的代碼看起來是這樣的:

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()是否發生() 。爲什麼set_xlim()在這種情況下不起作用?

+1

你可以試試'plt.xlim(...)'...我記得抓我的頭太大,幾個月前;-) – tamasgal

+1

我做了使用隨機整數一個簡單的測試,例如,從0到2000和'ax.set_xlim '適當地將x軸限制在0到1000之間。 – GWW

+0

兩個人留下了被刪除的好答案。 – Dan

回答

7

出於好奇,約在老xminxmax切換呢?

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) 
+0

這工作完美。由於我使用的是舊版本的matplotlib,這幾乎肯定是問題所在。 – Dan

9

本答案的原文摘錄於答案發布後幾乎立即刪除。

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) 
相關問題