将ATLAS样式应用于matplotlib绘图
atlasif的Python项目详细描述
大西洋化
Python包atlasify
将ATLAS样式应用于matplotlib绘图。这包括
- 切换到Arial字体(不是Helvetica,因为它不是广泛使用的)
- 在所有边上添加记号
- 往里爬
- 添加带有可选标签的ATLAS徽章(例如内部)
- 在徽章下方添加说明,以及
- 将ATLAS徽章移到轴区域之外。在
快速启动
该软件包将使用Helvetica。这个 包装附带GPL许可的Nimbus Sans L作为备用。在
atlasify
包可以使用pip安装。在
pip install atlasify# or pip install https://gitlab.cern.ch/fsauerbu/atlasify/-/archive/master/atlasify-master.tar.gz
使用
要应用基本样式,只需调用不带任何参数的方法。在
^{pr2}$标签
如果第一个参数是一个字符串,例如Internal
,它将被添加到后面
ATLAS徽章。在
plt.plot(x,y)atlasify("Internal")plt.savefig("test_2.pdf")
潜台词
第二个参数可用于在第二行添加文本。多行 独立渲染。在
plt.plot(x,y)atlasify("Internal","The Gaussian is defined by the\n""function $f(x) = e^{-x^2}$.\n")plt.savefig("test_3.pdf")
放大
通常没有足够的空间放置ATLAS徽章。通过
默认情况下,该方法将y轴放大1.3
。因素可以
使用enlarge
关键字参数进行更改。在
plt.plot(x,y)atlasify("Internal",enlarge=1.5)plt.savefig("test_4.pdf")
改变地图集
ATLAS升级的绘图没有标记为ATLAS本身。文本 徽章可以通过一个模块常量进行修改。在
importatlasifyasatlatl.ATLAS="ITk Strip"plt.plot(x,y)atlasify("Test beam")plt.savefig("test_9.pdf")
分辨率、字体和图形大小
字体大小在模块常量中定义,可以根据需要进行更改。 请注意,当 分辨率已更改。但是,徽章似乎更大的时候,数字 尺寸变小了。在
在下面两个不同分辨率的图中,徽章的分数相同 在画布上。在
plt.plot(x,y)atlasify("Internal")plt.savefig("test_5.png",dpi=72)plt.savefig("test_6.png",dpi=300)
当选择较小的体形尺寸时,徽章占 帆布。在
plt.figure(figsize=(4,3))plt.plot(x,y)atlasify("Internal")plt.savefig("test_7.pdf")
plt.figure(figsize=(4,4))heatmap=np.random.normal(size=(4,4))plt.imshow(heatmap)atlasify("Internal","Random heatmap, Outside badge",outside=True)plt.tight_layout()plt.savefig("test_8.pdf")
坐标轴标签
该模块提供了方便的方法set_xlabel()
和{monkeypatch_axis_labels()
更改默认对齐行为。在
fromatlasifyimportmonkeypatch_axis_labelsmonkeypatch_axis_labels()plt.figure(figsize=(4,3))plt.plot(x,y)plt.xlabel(r"$\phi$")plt.ylabel(r"Depth (a. u.)")atlasify("Internal")plt.tight_layout()plt.savefig("test_10.pdf")
示例
Real世界示例柱状图显示两个代表Z 玻色子背景和希格斯玻色子信号。在
# Unbinned dataZ=np.random.normal(90,10,size=10000)H=np.random.normal(125,10,size=1000)# Manual binning, or reading from TH1Fbins=np.linspace(50,200,31)Z_counts,_=np.histogram(Z,bins=bins)H_counts,_=np.histogram(H,bins=bins)plt.figure(figsize=(5,4))# Drawing shapesplt.hist(bins[:-1],bins=bins,weights=Z_counts,label="$Z$ boson",histtype='stepfilled')plt.hist(bins[:-1],bins=bins,weights=H_counts,bottom=Z_counts,label="Higgs boson",histtype='stepfilled')# Stylingplt.xlabel("Mass $m$ / GeV",ha='right',x=0.95)plt.ylabel("Events / 5 GeV",ha='right',y=0.95)plt.xlim((bins[0],bins[-1]))atlasify("Internal",r"$\sqrt{s} = 13\,\mathrm{TeV}$")plt.tight_layout()plt.savefig("test_histo.pdf")
- 项目
标签: