TGraph2D contour with exclusion band

Dear experts,

I have a TGraph2D drawn in cont4z option. Then I want to superimpose another TGraph2D
on the same pad to use one of its contours as the exclusion limit for the first plot.
I know how to put them on two pads, making the second pad transparent and so on.
However, The second TGraph2D is a complicated 2D graph. I have limited the number of contours to 2 by doing g->GetHistogram()->SetContour(2) to get the first contour.
This is fine and it works by showing only one contour superimposed on the background graph on the first pad.
However I want to have hashed style exclusion for the contour so that I show which region of the underlying graph is excluded by the first contour of the second graph on the second transparent pad.
Something like a TCutG but in a more automatic way …

Please give me your comments on how to do it.
I have attached what I want in approximate illustration.
Thanks

_ROOT Version:6.24
_Platform:Kubuntu 20.04
_Compiler:gcc 9.3


Screenshot_20210829_114942
Screenshot_20210829_114849

Maybe GetContourList will help you? Once you get the contour as graph, you can draw it with a fill “outside the area” (negative SetLineWidth).

1 Like

Oh thank you!
That must be the perfect solution.
Thank you so much.
Majid

Hi,
I managed to do it but with some tricks: (pad1 contains the main colorful plot, pad2 contains the exclusion band).
The contour TGraph2D has to be drawn first to fill the contour graphs.
Since I wanted only the graph, I deleted the mother contour plot at the end.
Another point is that gc (exclusion band) shows the hashed exclusion but not the main border line so I cloned it and manipulated the cloned graph to get the red line.

Thanks,
Majid

...
h[type]->Draw("cont list");
 pad2->Update();
  // Get Contours
  TObjArray *conts = (TObjArray*)gROOT->GetListOfSpecials()->FindObject("contours");
  TList* contLevel = NULL;
  TGraph* curv     = NULL;
  TGraph* gc       = NULL;
  TGraph* gcline       = NULL;
  
  contLevel = (TList*)conts->At(1);
  
  // Get first graph from list on curves on this level
  curv = (TGraph*)contLevel->First();
  
  gc = (TGraph*)curv->Clone();
  gcline = (TGraph*)gc->Clone();
  
  gcline->SetLineColor(kRed);
  gcline->SetLineWidth(5);
  gcline->Draw("C");
  gc->SetFillColor(kWhite);
  gc->SetFillStyle(3004);
  gc->SetLineWidth(300);
  gc->DrawClone("C");
  delete(h[type]);

I am surprise by this. Here is an example where exclusion and border are shown:

{
   const Int_t n = 35;
   Double_t xvalues[n], yvalues[n];
   for (Int_t i=0;i<n;i++) {
     xvalues[i]  = i*0.1;
     yvalues[i] = 10*cos(xvalues[i]);
   }

   auto gr = new TGraph(n,xvalues,yvalues);
   gr->SetLineColor(kBlue);
   gr->SetLineWidth(-2002);
   gr->SetFillStyle(3004);
   gr->SetFillColor(kRed);

   gr->Draw("AC");
}

Oh ok, thanks! It seems to have something to do with the line width.

For me, in a canvas with 4 pads, it is working now with these settings: (gc is the contour from the original 2D graph)

  gc->SetLineColor(kRed);
  gc->SetFillColor(kWhite);
  gc->SetFillStyle(3004);
  gc->SetLineWidth(502);

Screenshot_20210901_094308

If you see the link I provided, the last 2 digits are the line width, so you were specifying “no line”.

Exactly! Thanks again!

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