Hongquan Niu wrote: > > Hi, rooters, > > I want to draw a user defined function in two pads with > different parameter(not UserFunc parameter now if there is > any difference). I use > TF1 *func = new TF1("fit", UserFunc, -0.08, 0.44,0); > func->DrawCopy(); > First there is some complain but it can be drew. > Then I change some number and goto another pad and draw > it again. Then the plot in the first pad also changed. > I wonder how I can avoid this? > Hi Hongquan, You have to specify the parameters to the object, otherwise if you draw the same function several times, you will only see the last parameters. The TF1::Paint function is called when the pad/canvas needs to be updated. Paint will call your function to get the values. Root does not behave like a pen plotter ! It is very bad practice to have global variables in your program to specify the function parameters. This introduces fundamental limitations to object-oriented programming. Two examples: - the one you hit. In case of several pads representing the same function algorithm with different parameters. - if you want to save your function and read it into another program, the original values are lost or not available. Storing the current parameters together with the function object has only advantages. See example below. Rene Brun Double_t myfunc(Double_t *x, Double_t *par) { return par[0] + par[1]*x[0]; } void func2() { TCanvas *c1 = new TCanvas("c1","c1",600,800); c1->Divide(1,2); c1->cd(1); TF1 *func = new TF1("func",myfunc,0,10,2); func->SetParameters(1,1); func->DrawCopy(); c1->cd(2); func->SetParameters(1,0.5); func->Draw(); }
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:34 MET