【问题标题】:Adding axis limits in pyROOT在 pyROOT 中添加轴限制
【发布时间】:2022-01-11 12:32:17
【问题描述】:

我试图在我的 pyROOT 代码中限制我的 x 轴。现在 x 轴太长了,使我绘制的波形看起来太细了。我需要将 x 轴范围限制在 (130,240) 左右,但我尝试的所有操作都返回错误,因此我需要帮助。每当我在代码中使用 -> 时,它都会给我一个语法错误,我不知道为什么。下面是我需要添加 x 轴限制的代码。谢谢。。

import sys
sys.path.insert(1, "/home/diffuserdaq/DiffuserAnalysis/scripts")

import matplotlib
import matplotlib.pyplot as plt

import plot_waveformCOPY

from utilities.readscan import readscan

import ROOT


data = readscan("/home/diffuserdaq/DiffuserSetup/Oct13th_1.root","diffuser")

s0= data.scanpoints[0]

tgraph = ROOT.TGraph(len(s0.axis_time),s0.axis_time,s0.samples_PMT)

canvas = ROOT.TCanvas()
tgraph.Draw("ALP")
canvas.Print("plot.pdf")

gauss = ROOT.TF1("gaus","gaus",150,200)
gauss.SetParameter("Constant",-1.55)
gauss.SetParameter("Mean",185)
gauss.SetParameter("Sigma",5.0)

gauss.SetParLimits(0,-2.0,0.0)
gauss.SetParLimits(1,150.0,200.0)
gauss.SetParLimits(2,0.0,20.0)

fit_results = tgraph.Fit(gauss,"VBRS")
print("Fit Results",fit_results)

input(" press key to stop")

【问题讨论】:

    标签: limit axis pyroot


    【解决方案1】:

    在拨打canvas.Print("plot.pdf")之前,你可以试试:

    tgraph.GetXaxis().SetRangeUser(130, 240)
    

    关于 -> 运算符的用法,在 Python 中它的含义与在 C++ 中的含义不同,因此您永远不应该在访问类成员的上下文中使用它。始终使用点运算符。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-28
      • 2021-05-30
      • 1970-01-01
      • 2020-07-08
      • 2016-01-22
      • 1970-01-01
      • 2012-04-22
      相关资源
      最近更新 更多