import matplotlib.pyplot as plt
fig = plt.figure()?? #設(shè)置畫圖域??? 可以設(shè)置子圖的大小figsize=(3,3)? 等參數(shù)
ax1 = fig.add_subplot(2,2,1)?????? #在畫圖域中添加子圖打厘, 2x2個(gè)域中添加1號(hào)位的圖
#上面兩行代碼與下面一行代碼一樣
#fig,ax1 = plt.subplots(2,2)?? ? #在這里也可以指定figsize, ax1用來畫圖转绷,fig用來設(shè)置參數(shù)
#在第一個(gè)子圖上畫圖:ax[0,0].plot()
#官方文檔:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.subplots.html
ax2 = fig.add_subplot(2,2,2)?????? #添加2號(hào)位的圖
ax3 = fig.add_subplot(2,2,4)?????? #添加4號(hào)位的圖?????????????
ax1.plot([1,2,3,4,5],[1,2,3,4,5],c="blue",label="blue")???? #畫ax1圖,參數(shù)label設(shè)置圖例的名字
ax1.plot([4,3,2,1],[6,5,4,3],c="black",label="black")?????? #畫ax2圖
ax2.plot([1,2],[4,5],c="red")
ax1.legend(loc="best")???? #設(shè)置圖例廊佩,loc參數(shù)為位置
plt.show()???? #將所有圖都展示出
結(jié)果