折線圖篇
import matplotlib.pyplot as plt import numpy as np import pandas as pd #輸入因變量 y1 = [0.724266, 0.730357, 0.722058, 0.718748, 0.718975, 0.718422] y2 = [0.922546, 0.87944, 0.980582, 0.978843, 0.981803, 0.959068] y3 = [0.927972, 0.880988, 0.973044, 0.972353, 0.973717, 0.944803] y4 = [0.879261, 0.770276, 0.893485, 0.892955, 0.892227, 0.890149] #assert y1.shape[0]==y2.shape[0], '兩個因變量個數不相等!' fig,ax=plt.subplots(figsize=(6.4,4.8), dpi=100) #設置自變量的范圍和個數 x = ["BerNB", "MultiNB", "LogReg", "SVC" ,"LSVC", "NuSVC"] #畫圖 ax.plot(x,y1, label='bigram', linestyle='-', marker='*', markersize='10') ax.plot(x,y3, label='bigram_words', linestyle='--', marker='p', markersize='10') ax.plot(x,y2, label='jieba_feature', linestyle='-.', marker='o', markersize='10') ax.plot(x,y4, label='bag_of_words', linestyle=':', marker='x', markersize='10') #設置坐標軸 #ax.set_xlim(0, 9.5) #ax.set_ylim(0, 1.4) ax.set_xlabel('classifier', fontsize=13) ax.set_ylabel('F1-score', fontsize=13) #設置刻度 ax.tick_params(axis='both', labelsize=11) #顯示網格 #ax.grid(True, linestyle='-.') ax.yaxis.grid(True, linestyle='-.') #添加圖例 legend = ax.legend(loc='best') plt.show() fig.savefig('res/pic/1.png')
參數說明:
linestyle線的種類:
- 實線:'-'
- 虛線:'--'
- 點線:':'
- 杠點線:'-.'
marker參數在折線上打標記:
- 實心點:'.'
- 無標記:','
- 實心點:'o'
- 三角形(上下左右):'^' 'v' '<' '>'
- 無圈奔馳標(下上左右):'1' '2' '3' '4'
- 四邊形:'s'
- 五邊形:'p'
- 星標:'*'
- 六邊形(角向上邊向上):'h' 'H'
- 加號:'+'
- 叉號:'x'
- 瘦菱形:'d'
- 菱形:'D'
- 豎線:'|'
- 橫線:'_'
線條透明度選項:
- alpha = 0.1
參考文獻
1. https://blog.csdn.net/qq_26697045/article/details/8901862