Re: regarding fitting of curve

From: Olivier Couet <couet_at_mail.cern.ch>
Date: Thu, 12 May 2005 15:58:54 +0200 (CEST)

   

 Dear Sushil,  

  I think the following macro is what you want:  

 {

    c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);                                                                                  

    c1->SetGrid();                                                                                  

    const Int_t n = 20;
    Double_t x[n], y[n];
    for (Int_t i=0;i<n;i++) {

      x[i] = i*0.1;
      y[i] = 10*sin(x[i]+0.2);
    }
                                                                                 

    gr = new TGraph(n,x,y);

    gr->SetMarkerColor(4);
    gr->SetMarkerStyle(21);
    gr->SetTitle("a simple graph");
    gr->Fit("pol2");
    gr->Draw("AP");
                                                                                 

    TF1 *fit = gr->GetFunction("pol2");
    fit->SetLineColor(2);                                                                                  

    TLegend *legend=new TLegend(0.5,0.5,0.7,0.7);

    legend->SetTextFont(72);
    legend->SetTextSize(0.04);
    legend->AddEntry(gr,"Graph","p");
    legend->AddEntry(fit,"Fit","l");
    legend->Draw();
    legend->SetFillStyle(0);
    legend->SetBorderSize(0);
                                                                                 

 }    

 Cheers, Olivier      

> On Thu, 12 May 2005, Sushil Singh Chauhan wrote:
>
> > Dear Oliver,
> > Thanks for your reply. But I think you have not understood my querry
> > quit correctly may be i have not put it in right way.
> > Actually while ploting I am just using marker(as i have some data
> > points) and no lines. Once I get the plot then I fit this data points
> > with pol1 function using right click in fit pannel. But in the legend
> > the style of the line remain the same as it earleir.
> > Suppose I use the style "--------" in fitting but the legend box it
> > remain as "_________". I want to change this line style after the
> > fitting.
> > I hope it will give the idea about the problem i am facing.
> > with regards,
> > sushil.
> >
> >
> > On Thu, 2005-05-12 at 15:24, Olivier Couet wrote:
> > > Here is a small example. I guess it answers your two questions.
> > >
> > > Cheers, O.Couet
> > >
> > > {
> > > c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);
> > >
> > > c1->SetGrid();
> > >
> > > const Int_t n = 20;
> > > Double_t x[n], y[n];
> > > for (Int_t i=0;i<n;i++) {
> > > x[i] = i*0.1;
> > > y[i] = 10*sin(x[i]+0.2);
> > > }
> > >
> > > gr = new TGraph(n,x,y);
> > > gr->SetLineColor(2);
> > > gr->SetLineWidth(4);
> > > gr->SetMarkerColor(4);
> > > gr->SetMarkerStyle(21);
> > > gr->SetTitle("a simple graph");
> > > gr->Draw("ACP");
> > >
> > > TLegend *legend=new TLegend(0.5,0.5,0.7,0.7);
> > > legend->SetTextFont(72);
> > > legend->SetTextSize(0.04);
> > > legend->AddEntry(gr,"Graph","lp");
> > > legend->Draw();
> > > legend->SetFillStyle(0);
> > > legend->SetBorderSize(0);
> > > }
> > >
> > >
> > >
> > >
> > > On Thu, 12 May 2005, Sushil Singh Chauhan wrote:
> > >
> > > > Dear sir,
> > > > I am plotting some plots using root. I fist plot the data point and
> > > > then fit that using the option provided in the root.Finally the fitting
> > > > is shown by the lines. But I am facing some problem which are:
> > > >
> > > > 1) I am not able to put the same line in the legend box. As I am
> > > > plotting the two or more sets on the same plot so to distinguishe them i
> > > > need to put there corrosponding line(after fitting) style in the legend
> > > > box. I do not know how to do it. I saw the root mannual but I have not
> > > > found anything regarding this.
> > > > Is there any other way to do it?
> > > > 2) How can I remove the boundry of the legend box. I mean I do not want
> > > > to show the box in the plots.
> > > >
> > > > with best regards,
> > > > sushil.
> > > >
> >
>
>

-- 
Org:    CERN - European Laboratory for Particle Physics.
Mail:   1211 Geneve 23 - Switzerland                     Mailbox: J25910      
E-Mail: Olivier.Couet_at_cern.ch                            Phone:   +41 22 7676522
WWW:    http://cern.ch/Olivier.Couet/                    Fax:     +41 22 7670300
Received on Thu May 12 2005 - 15:59:00 MEST

This archive was generated by hypermail 2.2.0 : Tue Jan 02 2007 - 14:45:07 MET