Plotting TLines along with TMultigraph

Dear ROOT experts,

I am trying to plot lines on a TCanvas along with many polygons. Currently, I am representing each polygon with a TGraph, and adding them together into one TMultigraph. For the lines I am making use of TLines.

I need to draw the lines such that they are on top of one set of the polygons, but behind (obscured by) another set of polygons. Is this possible to do with a combination of TLine and TMultigraph or should I be using different ROOT classes? I tried representing the lines with two-point TGraphs added to the TMultigraph, but they would not show up when plotting the TMultigraph with a wide variety of draw options.

Cheers,
Michael

A multigraph contains on graphs.
The best way, in order to have only one multigraph, is to do TGraph with 2 points instead of TLines. Then you can choose the order

Hi,

Thanks for your reply. I also tried using TGraphs to represent the lines, as I mentioned above. It doesn’t seem to be working. Take a look at the code snippet below:

{
  TCanvas *c1 = new TCanvas();

  TMultiGraph *theMultiGraph = new TMultiGraph();

  Double_t plotX1[3] = {0.5, 0.7, 0.7};
  Double_t plotY1[3] = {0.5, 0.7, 0.3};
  TGraph *theGraph1 = new TGraph(3,plotX1,plotY1);
  theGraph1->SetFillColor(2);
  theGraph1->SetLineColor(2);

  Double_t plotX2[2] = {0.3, 1.1};
  Double_t plotY2[2] = {0.5, 0.5};
  TGraph *theGraph2 = new TGraph(2,plotX2,plotY2);
  theGraph2->SetLineColor(3);
  theGraph2->SetLineWidth(2.0);

  Double_t plotX3[3] = {0.9, 0.7, 0.7};
  Double_t plotY3[3] = {0.5, 0.3, 0.7};
  TGraph *theGraph3 = new TGraph(3,plotX3,plotY3);
  theGraph3->SetFillColor(4);
  theGraph3->SetLineColor(4);

  theMultiGraph->Add(theGraph1);
  theMultiGraph->Add(theGraph2);
  theMultiGraph->Add(theGraph3);

  theMultiGraph->Draw("AL");
  //theMultiGraph->Draw("AFL");                                                                                 

  //c1->SaveAs("test_AL.png");                                                                                  
}

I tried running this with the “AL” draw options and the “AFL” draw options, neither of which give me the result I’m looking for - in this case, I would like the green line to be on top of the red triangle, but hidden behind the blue triangle. Again, I’m trying to draw lines over some polygons, but not all of them - some polygons should obscure the lines. Changing the order in which I add the three TGraphs above doesn’t seem to affect anything.

I’ve also tried drawing the TMultiGraph with other TGraphs (using the “same” draw option) but that doesn’t seem to be working either.

Cheers,
Michael




I ll try your example tomorrow

Easy, simply do:

  theMultiGraph->Add(theGraph1,"F");
  theMultiGraph->Add(theGraph2, "L");
  theMultiGraph->Add(theGraph3, "F");
  theMultiGraph->Draw("A");

Wonderful! I wasn’t aware of this functionality of TMultiGraph::Add(). Thanks for your help.

–Mike

The examples in the doc use it a lot :slight_smile:
root.cern.ch/root/html/TMultiGraph.html