Fittting more than one function on same data set

Dear Users,

I am trying to fit more than one fitting functions on the same data set ( in terminal). However, when I fit the second function, it will replace the first one. Can you please tell me how to keep the outcome of both fitting functions on the canvas.

Thank you in advance.

Best regards,

You can use the “+” fit option.

Thank you so much.
Using “+” fit option helped . However, I would like to provide the legend (lines ) of two different colors to the fitting function. Using editor on canvas I can change the colors of fitting lines. However, in legend I am not able to change their colors. I tried using ( in terminal)

TLegendEntry *fun1 = legend->AddEntry(f1,"Fitting fun.");
TLegendEntry *fun2 = legend->AddEntry(f2,"Fitting fun.");

But nothing helps.
Can you please give some pointer regarding this.

With best regards,

Just supplement to previous reply, f1, f2 are the pointers to the two different defined fitting functions.

Do you have a small reproducer macro ?

This can happen, since that function plotted is a copied of the one you have defined previously for fitting.
You can either set the line color before fitting, or set the line color on the plotted function which you can retrieve using the method TH1::GetFunction(name)


Thank you for the hint. I tried to change the color of the function after the entry in legend using SetLineColor and while drawing again leg->Draw() changed the color of function line. Thank you so much.

I am sorry, I was using the terminal to make such a plot as it was straight forward. Thank you for your suggestions and finally I am able to draw what I wanted. :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.