2017-10-09 74 views
0

我有下面的代碼,我真的很努力地在整個屏幕上獲得情節。半屏上的Python圖情節

fig = plt.figure() 
fig.subplots_adjust(bottom=0.2) 
ax1 = fig.add_subplot(212) 
ax1.set_xlabel('Time') 
ax1.set_ylim(0,time) 
line1 = ax1.plot(a,'bo-',label='One') 
line2 = ax1.plot(b,'mo-',label='Two') 
lines = line1 + line2 
labels = [l.get_label() for l in lines] 
ax1.legend(lines, labels, loc=(0,-0.5), ncol=2) 
plt.show() 

我嘗試了所有我在網上找到的答案,所有的建議在線程Extend python plots to full screen,沒有一次成功。

任何幫助,將不勝感激!

P.S.我沒有使用

t = np.arange(b) 
plt.plot(t, a, 'bo-') 

的例子,因爲它如果x和y的值是不一樣的不工作,因爲它改變了我的計劃,我不能預先定義X。

+0

是什麼意思全屏顯示?你想要像'ax1 = fig.add_subplot(111)'這樣的單個子圖嗎? – sauerburger

+0

@sauerburger是的,這就是我以後的!感謝您的幫助!我遇到了這個例子https://pythonprogramming.net/subplot2grid-add_subplot-matplotlib-tutorial/,並被拋出去相信「212」代表完全不同的東西...... –

回答

0

ax1 = fig.add_subplot(212) 

創建2x1情節,並返回第二子情節。如果你想有一個單一的情節,此行更改爲

ax1 = fig.add_subplot(111) 

1x1分返回單個子情節。