绘制箱线图Drawing a Box Plot 2021-04-06 362- 2m- WikiPython科研注意:这篇文章上次更新于1961天前,文章内容可能已经过时。This article was last updated1961 days ago, the content may be outdated. 代码 Code 123456789101112131415161718192021222324252627282930313233343536373839404142import numpy as npimport matplotlib.pyplot as pltfrom matplotlib.pyplot import MultipleLocatorplt.rcParams['axes.unicode_minus']=False #显示负数# plt.rcParams["font.sans-serif"]=["SimHei"] # 显示中文plt.figure(figsize=(9,6))scores=(np.array([85,86,78,65,66,74,64,77,75,72,80,73,68,71,79])-5, np.array([86,58,68,78,79,74,62,66,60,72,73,77,61,78,84])-15, np.array([79,55,54,60,79,77,65,63,64,77,56,52,78,73,55])-15, np.array([92,86,73,75,84,70,69,72,77,70,78,76,68,88,83])-5, np.array([86,53,64,80,73,68,63,54,67,69,63,61,59,60,77])-15, np.array([75,49,65,73,65,61,62,64,53,58,56,54,72,69,74])-25, np.array([72,45,68,63,58,53,56,57,60,49,50,57,56,52,67])-30, np.array([90,85,75,87,70,86,82,83,79,86,73,85,89,83,72]))labels = ['Red channel','GDCP','UIBLA','Fusion-based','FUnIE-GAN','UGAN','UWCNN','Ours']plt.box(on=True)# plt.grid(b=None, which='major', axis='both') # 网格线plt.boxplot(scores,labels=labels,notch=True, meanline=True, showmeans=True)plt.ylabel("Preference Scores",fontproperties = 'Times New Roman',fontsize=16)plt.xticks(fontproperties = 'Times New Roman')plt.yticks(fontproperties = 'Times New Roman')## 修改 y 轴刻度间隔ax=plt.gca()y_major_locator=MultipleLocator(10)ax.yaxis.set_major_locator(y_major_locator)plt.ylim(-5,100) # y 轴范围# plt.title("主观评分")plt.savefig(r".//scores.png") # 保存成 pngplt.savefig('scores.pdf') # 保存成 pdfplt.show() # 显示 更多参考 [1] 设置新罗马字体 [2] 官方文档 More References [1] Setting the Times New Roman font [2] Official documentation 这也太可爱了,给我一点钱吧。I'm so cute. Please give me money.本文作者Post author:: Guangxin Wang本文链接Post link:: https://wgxls.site/posts/hzxxt/版权声明Copyright Notice:: 本博客所有文章除特别声明外,均默认采用 许可协议。All articles in this blog are licensed under unless otherwise stated.