我完全新的Matplotlib和我寫了這個代碼繪製兩個系列,到目前爲止,是工作的罰款:Matplotlib:在劇情增加了第三次要情節
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
list1 = [1,2,3,4]
list2 = [4,3,2,1]
somecondition = True
plt.figure(1) #create one of the figures that must appear with the chart
gs = gridspec.GridSpec(3,1)
if not somecondition:
ax = plt.subplot(gs[:,:]) #create the first subplot that will ALWAYS be there
ax.plot(list1) #populate the "main" subplot
else:
ax = plt.subplot(gs[:2, :])
ax.plot(list1)
ax = plt.subplot(gs[2, :]) #create the second subplot, that MIGHT be there
ax.plot(list2) #populate the second subplot
plt.show()
我希望做的是加入第三系列此圖,讓我們說:
list3 = [4,1,2,4]
重要的是,第一副區(列表1)必須是兩倍,比其他兩個大;爲此,我使用了gridspace,但由於我真的很新,所以我無法理解如何爲此示例代碼設置參數以獲取第三個參數。任何人都可以解釋我應該如何編輯塊somecondition == True
以獲得3個子圖(前兩個比下面的其他兩個大兩倍),而不僅僅是兩個? P.S.該代碼是可執行的。
非常感謝,它非常完美。 –