简体   繁体   English

在 pyROOT 中添加轴限制

[英]Adding axis limits in pyROOT

I am trying to limit my x-axis in my pyROOT code.我试图在我的 pyROOT 代码中限制我的 x 轴。 Right now the x-axis is way too long and makes the waveform that I am plotting look too thin.现在 x 轴太长,使我绘制的波形看起来太细。 I need to limit the x-axis range to about (130,240) but everything I try comes back with an error so I need help.我需要将 x 轴范围限制在 (130,240) 左右,但我尝试的所有操作都返回错误,因此我需要帮助。 Any time I use a -> in the code it gives me a syntax error and I do not know why.每当我在代码中使用 -> 时,它都会给我一个语法错误,我不知道为什么。 Below is my code that I need the x-axis limit added to.下面是我需要添加 x 轴限制的代码。 Thank you..谢谢..

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

Before calling canvas.Print("plot.pdf") , you can try:在调用canvas.Print("plot.pdf")之前,您可以尝试:

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

Regarding the usage of the -> operator, in Python it has not the same meaning as it has on C++, so you should never use it in the context of accessing a class member.关于->运算符的用法,在 Python 中它的含义与在 C++ 中的含义不同,因此您永远不要在访问 class 成员的上下文中使用它。 Always use the dot operator instead.始终使用点运算符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM