[問題] 有關matplotlib多圖合併

看板Python作者 (我可以重來嗎)時間6年前 (2018/05/01 23:39), 編輯推噓1(1010)
留言11則, 3人參與, 6年前最新討論串1/1
各位先進好 我將資料繪製多圖如下 import matplotlib.pyplot as plt #交易價作圖 %matplotlib inline plt.rcParams['font.family']='DFKai-SB' #顯示中文 plt.style.use('ggplot') ax = df_l_t_p.plot(x = df_l_t_p.index, figsize=(12,5), fontsize=10,kind='line',style='-o') ax.yaxis.tick_right() fig_title = '玉荷包批發市場交易均價(元/公斤)'+yyymmdd plt.title(fig_title, fontsize=30) fig_file_name = '水果-玉荷包'+yyymmdd+'.png' plt.savefig(fig_file_name) plt.show() 以及 import matplotlib.pyplot as plt #交易價作圖 %matplotlib inline plt.rcParams['font.family']='DFKai-SB' #顯示中文 plt.style.use('ggplot') ax = df_mang_t_p.plot(x = df_mang_t_p.index,figsize=(12,5),fontsize=10,kind='line',style='-o') ax.yaxis.tick_right() fig_title = '金煌批發市場交易均價(元/公斤)'+yyymmdd plt.title(fig_title, fontsize=30) fig_file_name = '水果-金煌'+yyymmdd+'.png' plt.savefig(fig_file_name) plt.show() 單張作業可以,但我想進行多圖合併 查詢為subplot的語法 但嘗試許久多為錯誤, 請問該如何寫呢? 萬分感謝~ -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.218.124.102 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1525189186.A.C10.html

05/02 01:48, 6年前 , 1F
如果要用subplot的話,大概是這樣的結構:
05/02 01:48, 1F

05/02 01:49, 6年前 , 2F
plt.subplot(rows, cols, 1) # 第一個子圖
05/02 01:49, 2F

05/02 01:50, 6年前 , 3F
plt.plot(x, y) #畫圖
05/02 01:50, 3F

05/02 01:51, 6年前 , 4F
plt.subplot(rows, cols, 2) #第二場子圖
05/02 01:51, 4F

05/02 01:51, 6年前 , 5F
plt.plot(x, y) #之後就重複這樣的步驟就好
05/02 01:51, 5F

05/02 07:14, 6年前 , 6F
df_l_t_p.plot(x = df_l_t_p.index, figsize=(12,5)
05/02 07:14, 6F

05/02 07:14, 6年前 , 7F
,我一直覺得會不會是我這樣寫其實是錯的,我的語法
05/02 07:14, 7F

05/02 07:14, 6年前 , 8F
沒有y?
05/02 07:14, 8F

05/02 16:47, 6年前 , 9F
fig, axes = plt.subplots(2, 2)
05/02 16:47, 9F

05/02 16:48, 6年前 , 10F
axes[0, 0].plot(x, y)
05/02 16:48, 10F

05/02 16:48, 6年前 , 11F
我是類似這樣寫覺得比較清楚
05/02 16:48, 11F
文章代碼(AID): #1Qw8f2mG (Python)