Lego with multiple fill colours?

Hello,

I can’t fill the Lego plot with multiple colors like it’s in
root.cern.ch/root/roottalk/roottalk04/0393.html

In the next script the option “same” does not work at all:
TH2D h = new TH2D(“h”,“hfun”,10,-1.,1.,10,-1.,1.);
const Int_t n = 1000000;
for (Int_t i=0;i<n;i++) {
Double_t x = -1.+2
gRandom->Rndm();
Double_t y = -1.+2gRandom->Rndm();
Double_t z = abs(sin(x)
(1.+cos(y)));
h->Fill(x,y,z);
}
h->SetFillColor(3);
h->DrawCopy(“LEGO1”);
h->SetFillColor(7);
h->GetXaxis()->SetRange(5,6);
h->GetYaxis()->SetRange(4,7);
h->DrawCopy(“sameLEGO1”);

What is wrong?

Regards

I would recommend to use a THStack like in the following 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");
}


OK,
Thank you.
The using of THStack for LEGO coloring was mentioned in the early roottalk messages.

Regards