matplotlib绘制图像设置中文宋体,英文新罗马,字体大小7.5,坐标轴刻度线内侧

    科技2022-07-15  141

    import matplotlib import numpy as np import matplotlib.pyplot as plt from matplotlib import rcParams matplotlib.use("pgf") pgf_config = { "font.family": 'serif', "font.size": 7.5, #字体大小7.5 "pgf.rcfonts": False, "text.usetex": True, "pgf.preamble": [ r"\usepackage{unicode-math}", r"\setmainfont{Times New Roman}", r"\usepackage{xeCJK}", r"\setCJKmainfont{SimSun}", ], } rcParams.update(pgf_config) plt.rcParams['xtick.direction'] = 'in' plt.rcParams['ytick.direction'] = 'in'#刻度内测,out外侧 x = [1,2,3,4,5] y_y=[0.5,0.6,0.7,0.8,0.9]#原始图片 #plt.rcParams['font.sans-serif'] = ['Microsoft YaHei'] #plt.rcParams['axes.unicode_minus'] = False #plt.figure(50) for i in range(len(y_y)): plt.text(x[i], y_y[i]+0.01, '%.3f' %(y_y[i]),ha='center') plt.plot(x, y_y,'rp--')#,label='Integrated algorithm' #plt.plot(x, y_1,'bp--',label='01') #plt.plot(x, y_2,'rp--',label='03') #plt.plot(x, y_200,'gp-',label='data=200') # set x limits plt.xlim((0.8, 5.2)) plt.ylim((0.8, 1)) plt.xticks(x) #plt.xlabel('Number of data preprocessing',fontsize=13)#########x轴代表 plt.xlabel('横纵') plt.ylabel('纵轴')############y轴代表 plt.title('标题')###########title 14 #plt.legend(loc='upper left',fontsize=13) #plt.show() plt.savefig('./集成2.png', dpi=800)

    第一次运行需要安装插件,需要等待一会,安装完毕重新运行等待运行结束,查看保存图片的路径即可

    Processed: 0.010, SQL: 8