I am trying to limit my x-axis in my pyROOT code. Right now the x-axis is way too long and makes the waveform that I am plotting look too thin. 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. 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. 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:
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. Always use the dot operator instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.