Rename p0, p1

As i wrote in Print Parameters into Legend, i’m trying to print the Fit parameter in the legend. Now i use

to Print the Parameters (not in the TLegend, but it is at least shown). My problem now is to rename the Parameters. There are named “p0” and “p1”, i want them named “y-intersect” and “slope”. I tried

TF1 fitfj1("Linear law","[0]+x*[1]",-5,5); fitfj1.SetLineColor(kRed); fitfj1.SetLineStyle(2); fitfj1.SetParName(0,"Y-Intersect") fitfj1.SetParName(1,"Slope") fj1.Fit(&fitfj1);
while fj1 is the Import of xy, the fit goes through. The SetParName does not change anything.
Please help me.

Thanks in advance!

audiophiel

In principle what you are doing is correct …
Can you post a small running macro showing your problem ?

my whole code is attached to this post.
farad_1.C (2.21 KB)

It would be easier for me to help you if you send a self-contains running example. What you sent gives me:

Processing farad_1.C...
Error in <TGraphErrors::TGraphErrors>: Cannot open file: messdaten/faraday_j_1.txt, TGraphErrors is Zombie
Warning: fitfj1.SetParName(0,"Y-Intersect") Missing ';' farad_1.C:14:
Warning: fitfj1.SetParName(1,"Slope") Missing ';' farad_1.C:15:
Warning in <Fit>: Fit data is empty 


Y-intersect: 0
Y-intersect error: 0
Slope 0
Slope error 0


Error in <TGraphErrors::TGraphErrors>: Cannot open file: messdaten/faraday_j_2.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Error in <TGraphErrors::TGraphErrors>: Cannot open file: messdaten/faraday_s_1.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Error in <TGraphErrors::TGraphErrors>: Cannot open file: messdaten/faraday_s_2.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Info in <TCanvas::Print>: pdf file Faradayeffekt.pdf has been created
root [1] .q
imaccouet:Downloads couet$ vi farad_1.C 
imaccouet:Downloads couet$ .x
root [0] .x farad_1.C
Error in <TGraphErrors::TGraphErrors>: Cannot open file: messdaten/faraday_j_1.txt, TGraphErrors is Zombie
Warning: fitfj1.SetParName(0,"Y-Intersect") Missing ';' farad_1.C:14:
Warning: fitfj1.SetParName(1,"Slope") Missing ';' farad_1.C:15:
Warning in <Fit>: Fit data is empty 


Y-intersect: 0
Y-intersect error: 0
Slope 0
Slope error 0


Error in <TGraphErrors::TGraphErrors>: Cannot open file: messdaten/faraday_j_2.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Error in <TGraphErrors::TGraphErrors>: Cannot open file: messdaten/faraday_s_1.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Error in <TGraphErrors::TGraphErrors>: Cannot open file: messdaten/faraday_s_2.txt, TGraphErrors is Zombie
Warning in <Fit>: Fit data is empty 
Info in <TCanvas::Print>: pdf file Faradayeffekt.pdf has been created

sorry. i compressed al needet files to an .zip file (attached).
farad.zip (16.5 KB)

You made a syntax error. The “;” is missing at the end of the lines “fitfj1.SetParName” … add it and it will work.

i feel realy stupid right now.
thank you for your time.

no problem :slight_smile: