学无先后,达者为师

网站首页 编程语言 正文

matplotlib按照论文要求绘图并保存pdf格式

作者:别出BUG求求了 更新时间: 2023-11-13 编程语言

学术论文的图绘制要求:

  1. 尽量清楚, 字体、曲线、标记尽量大
  2. 分辨率要求,最低dpi要求,例如dpi最低300
  3. 保存格式,例如pdf
  4. 无颜色印刷,需要标记来区分类别

演示实例:

    font_size = 13 #字体大小
    label_size = 11.5 #label
    lw = 2 #线宽
    font = fm.FontProperties(size=font_size)
    
    for results in complet_results:
        if results['mode'] == 'method1':
            label = 'method1'
            marker = 'o'
        elif results['mode'] == 'method2':
            label = 'method2'
            marker = '+'
        elif results['mode'] == 'method3':
            label = 'method3'
            marker = '*'

        plt.plot(results['test_acc_global'], label=label,  marker=marker, linewidth=lw)

    # plt.title(data_name, fontsize=font_size)
    plt.xlabel('Rounds', fontproperties=font)
    plt.ylabel('Test Acc', fontproperties=font)
    plt.grid() #可选
    plt.xlim(0, 100) #x轴显示范围
    plt.ylim(0.75, 0.91) #y轴显示范围
    plt.legend(shadow=False, fontsize=font_size, loc=4) #图例
    plt.tick_params(labelsize=label_size) #刻度大小
    save_path = os.path.join(save_dir, '{}_test_acc_detail'.format(data_name.replace(',', '_')))
    plt.savefig(save_path+'.jpg' , dpi=300, bbox_inches='tight') #dpi
    plt.savefig(save_path+'.pdf', bbox_inches='tight') #pdf
    plt.show()
    plt.close()

原文链接:https://blog.csdn.net/weixin_39589455/article/details/129649549

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新