Error bar and line style in a TGraphErrors

Hi all,

I have created a TGraphError object and I am trying to plot it with a dashed (or dotted) line connecting the markers and with error bars represented by a continuous line.

At the moment, I am plotting the graph with the options PL.

However, if I change the line style, the same line style is applied to the line connecting the markers and to the error bars. Is it possible to apply different line styles to the error bars and to the line connecting the markers?

There is now only one line style for all the lines produced by a TGraphErrors. To have different linestyle you need to use DrawCopy or produce 2 graphs like in the following macro:

{
   c1 = new TCanvas("c1","A Simple GraphErrors Example",200,10,700,500);
   const Int_t n = 20;
   Double_t x[n], y[n], ex[n], ey[n];
   for (Int_t i=0;i<n;i++) {
     x[i]  = i*0.1;
     y[i]  = 10*sin(x[i]+0.2);
     ex[i] = 0.08;
     ey[i] = 0.1*i;
   }
   TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey);
   gr->SetLineStyle(1);
   gr->Draw("AP");
                                                                                
   TGraphErrors *gr2 = new TGraphErrors(n,x,y,ex,ey);
   gr2->SetLineStyle(4);
   gr2->Draw("L");
}

We’ll think of a better solution like adding SetErrorLineStyle …

Thanks for your help… I think I will produce a couple of graphs because, for what I know, the DrawCopy method works for histograms but not for TGraph objects.

Hi Couet,

     Yes I think adding an independent error bar style is definitely needed... but seems it's not yet available currently ( I'm using 5.28.00 for this moment ).

Manqi

[quote=“couet”]There is now only one line style for all the lines produced by a TGraphErrors. To have different linestyle you need to use DrawCopy or produce 2 graphs like in the following macro:

{
   c1 = new TCanvas("c1","A Simple GraphErrors Example",200,10,700,500);
   const Int_t n = 20;
   Double_t x[n], y[n], ex[n], ey[n];
   for (Int_t i=0;i<n;i++) {
     x[i]  = i*0.1;
     y[i]  = 10*sin(x[i]+0.2);
     ex[i] = 0.08;
     ey[i] = 0.1*i;
   }
   TGraphErrors *gr = new TGraphErrors(n,x,y,ex,ey);
   gr->SetLineStyle(1);
   gr->Draw("AP");
                                                                                
   TGraphErrors *gr2 = new TGraphErrors(n,x,y,ex,ey);
   gr2->SetLineStyle(4);
   gr2->Draw("L");
}

We’ll think of a better solution like adding SetErrorLineStyle …[/quote]

What kind of plot do you want to achieve ?
I think the technique previously explained should work in your case.
We are always a bit reluctant to add new data members in TGraph because this class should
remains as small as possible as it is used by many other classes.