Too much space between the dots in the dotted line style

Hi,
I have two sets of data: one theoretical and another experimental (for example). I want one of them to be a solid line and the other to be a dotted line in a TMultiGraph. Here is the result:

The dotted line corresponds to TGraph->SetLineStyle(2). As you can see, when the parabola is “closed” there is too much space between the dots.

If I try TGraph->SetLineStyle(9):

Now the “opened” parabolas seem to be a solid line. I have tried all the deafult styles.

This macro is related to this one.


ROOT Version: 6.24/06
Platform: Debian
Compiler: Not Provided


Hi @acgc99,

Most probably the SetLineStyle(9) only has to be applied to the last canvas partition (TPad). If your code is besed on the link you provided, a quick-and-dirty fix would be as follows:

if (i ==3)
   gr->SetLineStyle(9);

Cheers,
J.

You can also define your own line style with gStyle->SetLineStyleString(...);, see the documentation.

@jalopezg , I thought about the dirty solution, but I shared only one plot, there are five different plots with different results… that will become very dirty. Probably is the best solution if I want to avoid defining new styles.

Maybe @couet can also provide some suggestion here.

@dastudillo , the best I found is gStyle->SetLineStyleString(11,"4 2").

But it does not work for all frames… I don’t know how the distances are calculated, the doc says:

A line is a suite of segments, each segment is described by the number of pixels. The initial and alternating elements (second, fourth, and so on) are the dashes, and the others spaces between dashes.

But I see that the separation between the segments is not a constant. I’m confused.

Details here:
https://root.cern/doc/master/classTAttLine.html#ATTLINE3

{
   TCanvas *c1 = new TCanvas("c1","c1",200,10,700,500);
   c1->Divide(4,1);

   c1->cd(1);
   TF1 *f1 = new TF1("f1","150*x*x",-6,6);
   f1->SetLineColor(2);
   f1->SetLineStyle(2);
   f1->Draw();
   TF1 *f2 = new TF1("f2","x*x",-6,6);
   f2->SetLineColor(4);
   f2->SetLineStyle(2);
   f2->Draw("same");

   c1->cd(3);
   const Int_t n = 10;
   Double_t x[n] = {-0.22, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
   Double_t y[n] = {1, 12.9, 35.6, 67.4, 79, 90.6, 80.7, 36.3, 14.5, 1};

   TGraph *gr = new TGraph(n,x,y);
   gr->SetLineColor(2);
   gr->SetLineStyle(2);
   gr->SetLineWidth(2);

   Double_t y2[n] = {2.0, 1.9, 1.8, 1.7, 1.6, 1.5, 1.6, 1.7, 1.8, 1.9};
   TGraph *gr2 = new TGraph(n,x,y2);
   gr2->SetLineColor(4);
   gr2->SetLineStyle(2);
   gr2->SetLineWidth(2);

   TMultiGraph *mgr = new TMultiGraph();
   mgr->Add(gr);
   mgr->Add(gr2);
   mgr->Draw("AL");
   return;
}

If you run this, do you get the same as here, or still bad spacing?

Yes, that works. Since I couldn’t reproduce the problem in a simplier code, I found a dirty solution:

gr->SetMarkerStyle(20);
gr->SetMarkerSize(0.25);
mg->Add(gr, "P");

and play with the independent variable to have equally spaced points.

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