先上效果圖:
import matplotlib.pylab as plt # 導(dǎo)入繪圖包import matplotlib.pyplot as mpimport numpy as np
再開始繪圖:
x_lambda=range(11) #x軸# 左側(cè)y軸:y1_recally1_recall=[0.746535121682016,0.7478350797262016,0.7495115054452305,0.7496154512070707,0.7498688766858469,0.7495455257754897 ,0.7495684090706842,0.7495684090706842,0.7495684090706842,0.7495684090706842,0.7495684090706842]# 右側(cè)y軸:y2_preceisey2_preceise=[0.47455049019122314,0.4756946549509488,0.4762285985054871,0.4762667373308113,0.4764955702827563, 0.47645743145743213,0.4764955702827563,0.4764955702827563,0.4764955702827563,0.4764955702827563, 0.4764955702827563] mp.gcf().set_facecolor(np.ones(3) * 240/255)#設(shè)置背景色fig, ax1 = plt.subplots() # 使用subplots()創(chuàng)建窗口# 繪制折線圖像1, 標(biāo)簽,線寬ax1.plot(x_lambda, y1_recall, c='orangered', label='recall', linewidth = 1) mp.legend(loc=2)ax2 = ax1.twinx() # 創(chuàng)建第二個坐標(biāo)軸ax2.plot(x_lambda, y2_preceise, c='blue', label='preceise', linewidth = 1) #同上, 'o-'mp.legend(loc=4)plt.grid(True) # 樣式風(fēng)格:網(wǎng)格型ax1.set_title("Double Y axis",size=22) # 大標(biāo)題ax1.set_xlabel('lambda',size=18) ax1.set_ylabel('recall',size=18)ax2.set_ylabel('preceise',size=18)# mp.gcf().autofmt_xdate() # 自動適應(yīng)刻度線密度,包括x軸,y軸plt.show()
聯(lián)系客服