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线的种类:
- 实线:'-'
- 虚线:'--'
- 点线:':'
- 杠点线:'-.'
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