python畫論文中的折線圖


 

折線圖篇

 

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線的種類:

  1. 實線:'-'
  2. 虛線:'--'
  3. 點線:':'
  4. 杠點線:'-.'

marker參數在折線上打標記:

  1. 實心點:'.'
  2. 無標記:','
  3. 實心點:'o'
  4. 三角形(上下左右):'^' 'v' '<' '>'
  5. 無圈奔馳標(下上左右):'1' '2' '3' '4'
  6. 四邊形:'s'
  7. 五邊形:'p'
  8. 星標:'*'
  9. 六邊形(角向上邊向上):'h' 'H'
  10. 加號:'+'
  11. 叉號:'x'
  12. 瘦菱形:'d'
  13. 菱形:'D'
  14. 豎線:'|'
  15. 橫線:'_'

線條透明度選項:

  1. alpha = 0.1

 

 

參考文獻

1. https://blog.csdn.net/qq_26697045/article/details/8901862

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM