将ATLAS样式应用于matplotlib绘图

atlasif的Python项目详细描述


大西洋化

Pipeline statusPylint scoreGNU AGPLv3PyPI

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}$

ATLAS style plot

标签

如果第一个参数是一个字符串,例如Internal,它将被添加到后面 ATLAS徽章。在

plt.plot(x,y)atlasify("Internal")plt.savefig("test_2.pdf")

ATLAS style plot

潜台词

第二个参数可用于在第二行添加文本。多行 独立渲染。在

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 style plot

放大

通常没有足够的空间放置ATLAS徽章。通过 默认情况下,该方法将y轴放大1.3。因素可以 使用enlarge关键字参数进行更改。在

plt.plot(x,y)atlasify("Internal",enlarge=1.5)plt.savefig("test_4.pdf")

ATLAS style plot

改变地图集

ATLAS升级的绘图没有标记为ATLAS本身。文本 徽章可以通过一个模块常量进行修改。在

importatlasifyasatlatl.ATLAS="ITk Strip"plt.plot(x,y)atlasify("Test beam")plt.savefig("test_9.pdf")

ATLAS style plot

分辨率、字体和图形大小

字体大小在模块常量中定义,可以根据需要进行更改。 请注意,当 分辨率已更改。但是,徽章似乎更大的时候,数字 尺寸变小了。在

在下面两个不同分辨率的图中,徽章的分数相同 在画布上。在

plt.plot(x,y)atlasify("Internal")plt.savefig("test_5.png",dpi=72)plt.savefig("test_6.png",dpi=300)

ATLAS style plotATLAS style plot

当选择较小的体形尺寸时,徽章占 帆布。在

plt.figure(figsize=(4,3))plt.plot(x,y)atlasify("Internal")plt.savefig("test_7.pdf")

ATLAS style plot

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")

ATLAS style plot

坐标轴标签

该模块提供了方便的方法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")

ATLAS style plot

示例

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")

ATLAS style plot

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java重写父类中的特定行   java Apache Commons CLI订购帮助选项?   java如何将数据添加到网格视图   java如何在Apache Camel批处理后移动文件?   java如何为日期范围的between子句编写hql查询?   雅加达ee开始Java编程,我应该从哪里开始?   排序Java8+流:检查我的objectinstances的两个字段的列表顺序是否正确   java如何将json转换为Map<String,Object>确保整数为整数   java不能在Spring数据JPA批处理过程中创建TransactionException   java损坏的PDF文件从FTP下载到使用Apache Common Net的设备   java无法使用Spring批处理和Wso2为XML架构命名空间找到Spring NamespaceHandler   java Android ImageView未显示在SherlockFragment中   Maven在构建时出错=无法识别Java路径   java如何使用批处理文件调用关闭处理程序?   java admob广告横幅重叠我的游戏屏幕安卓