Multiple TGraph (or TH1) in perspective

Dear rooters,

I am trying to represent many TGraph in perspective, like the picture attached to this post. For visibility they have to be filled (ideally with a palette !). Note that in the example the 3rd axis does not matter but in the case I am presently trying to build yes.

I tried many things w/o success. For example TPolyMarker(s) or TPolyLine(s) but I can not fill them. Or TH2F but the 3D option like “LEGO” usually fill the side with white and “SURF” is too fancy.

Is there any easy way to produce such a result ?

Note that TGraph (or better TGraph2D to include the 3D dimension value) is very convenient since I can read the data directly from a ASCII file.

Thank you in advance for the help.
Best
Julien

Maybe this macro help

Jan



hperspective.C (1.76 KB)

Dear Jan,

Thank you for your macro.
Indeed it is a very elegant solution that solves most of my problem.

I will also like to have the possibility to draw a Z-axis in some cases, and I believe modifying your code will make it.

I still think that a special draw option, is not to complicated, for a TGraph2D will be nice thought.

Best
Julien

Ps: I tested your macro in more details. There is one issue: you write the pads from front to back which makes the histogram overlap. If I draw the pads from back to front to avoid this then I end up with superimposed white line which comes from the pad frame. How can I remove (or make it transparent) the frame ?


Dear rooters,

I come back to this post after more testing, looking for a solution to remove the line around the pad. I did not really find it.

Is there any solution to do so ? (see picture above)

Best
Julien

I do not see these white lines around the pads with the macro hperspective.C. I get exactly the same picture as the first one sent. I am using the last ROOT version on linux. Which ROOT version are you using ?

Dear Olivier,

Which version of the macro did you use?
The one than Jan proposed draw the pad from front to back. I just inverted the loop to draw them back to front (I attached the code to this post).

In any case: I am on Mac OS 10.4.11 with the last version of ROOT (5.19/04).

Best
Julien
hperspective-modified.C (1.89 KB)

Well, I was using the only one available … I will try your now.

The border is always painted, and there is no option to turn it off in the current ROOT version. One technique I can think of which might work, would be to first paint all the axis (empty histogram with the correct range) and then paint on top the histograms using the option SAME. When option SAME is used the frame is not paint again.

Dear Olivier,

I followed your suggestion and first draw the pad from back to front and the histogram axis and then came back to the pads one by one plotting only the the histogram (with the option “same”). Unfortunately the pad seems to be drawn again. Here the part of the code in the plotting loop :

for(Int_t p=0;p<2;p++){
    for (Int_t i = nh-1; i >= 0; i--) {
    // make pad
    c->cd(0);
    if(p==0){
      pad[i] = new TPad(Form("pad_%d", i + 1), "", i*xdel, i*ydel,
			(i + 1)*xdel + xsize, (i + 1)*ydel + ysize);
      pad[i]->SetNumber(i + 1);
      pad[i]->SetFrameFillStyle(4000);
      pad[i]->SetFillStyle(4000);
      pad[i]->SetFrameLineColor(kWhite);
      pad[i]->SetFrameLineWidth(0);
      pad[i]->SetFrameBorderMode(0);
      pad[i]->SetFrameBorderSize(0);
      pad[i]->Draw();
    }
    pad[i]->cd();


    // draw histo
    h = (TH1F *)hlist->FindObject(Form("h_%d", i));
    //    h->SetFillStyle(3001);
    Int_t c1 = 50, c2 = 200, c0 = (c2 - c1)/nh;
    h->SetFillColor(TColor::GetColor(c1 + i*c0, 0, c2 - i*c0));
    h->SetStats(0);
    if (i != 0) {
      h->GetXaxis()->SetLabelOffset(9999);
      h->GetYaxis()->SetLabelOffset(9999);
    }

    if(p==0) h->Draw("AXIS");
    else h->Draw("SAME");
    }
  }

In any case there is no draw option with TGraph2D, TH2F or TH3F that will allow me to do almost the same ?

Best
Julien

You can fill a TH2 and plot it as a lego. Or if you want to have different color for each histogram you can create several TH2 fill them shifted one from each other, put them in a THStack and draw it… Yes, I guess a THSTack would be the best.

One solution exist (but working only with PostScript interface)gStyle->SetLineStyleString(11, "0 9999"); pad->SetFrameLineStyle(11);

Jan

Dear Jan and Olivier,

I did not have time to carefully test the THStack solution. If I can I will and report it here for everyone’s information.

In in case the PostScript solution is already very good (we can convert in the worst case). I tested on my Mac and it works.

Thank you for your time and help.

Best
Julien

THstack example:

{
        Int_t n  = 39;
        Int_t nb = 7; 
        TH2D *hist[n];
        THStack *a = new THStack("a","LegoPlot");

        for(Int_t ihist=0; ihist<n; ihist++ ) {
              TString hn="hist_"; hn+=ihist;
              hist[ihist] = new TH2D(hn,hn,nb,0,nb,10,0,10);
              hist[ihist]->SetBinContent(ihist+1,ihist,double(ihist));
              hist[ihist]->SetBinContent(ihist  ,ihist,double(ihist));
              hist[ihist]->SetBinContent(ihist-1,ihist,double(ihist));
              hist[ihist]->SetFillColor(ihist);
              a->Add(hist[ihist]);
        }
        a->Draw("LEGO10");
}