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

2023-05-16

学术论文的图绘制要求:

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

一个绘图示例

    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()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

matplotlib按照论文要求绘图并保存pdf格式 的相关文章

随机推荐