void ZOffset3D( TH3* h, float z0) { // This boosts the height for each bin of a histogram by a given constant value of z int nbinx = h->GetNbinsX(); int nbiny = h->GetNbinsY(); int nbinz = h->GetNbinsZ(); for (int i=1; i<=nbinx; i++) { for (int j=1; j<=nbiny; j++) { for (int k=1; k<=nbinz; k++) { int h0=(h->GetBinContent(i,j,k)); if (h0>0){h->SetBinContent(i,j,k,z0+h0);} } } } h->SetMinimum(0); } void NewPalette(int top, int z0,int MaxCol, int MinCol){ Int_t palette[top]; int q0; int co; for (int qq=0;qq=z0){ // Set the rest of the values between MinCol and Max co= (MinCol+(MaxCol-MinCol)*q0*pow(top-z0,-1)); palette[qq]=co; } } gStyle->SetPalette(top,palette); } void Many3DHistograms(int Nc, int N){ // Nc is the number of planes I want, N is the ammount of bins on each axis per plane TCanvas * c16 = new TCanvas("c16","c16",600,400); gStyle->SetCanvasPreferGL(true); gStyle->SetOptStat(kFALSE); Float_t Xh[N+1],Yh[N+1],Zh[2*Nc]; int cc2=0; int Z[Nc]; //The distances between histograms for (int cc=0;ccRndm()); int y1=N*(gRandom->Rndm()); int xL=N*(gRandom->Rndm()); int yL=N*(gRandom->Rndm()); int z1=Z[0]-10; int zL=Z[Nc-1]+10; int XL0[2],YL0[2], ZL0[2]; XL0[0]=x1;YL0[0]=y1;XL0[1]=xL;YL0[1]=yL; ZL0[0]=z1; ZL0[1]=zL; int Nin=2000;//Nin events for (int c=0;cRndm()); yc=N*(gRandom->Rndm()); h->Fill(xc,yc,zc); } } ZOffset3D(h, 100); int T=h->GetMaximum(); NewPalette(T, 100,19,12); //greys, works great TPolyLine3D *g2 = new TPolyLine3D(2, XL0, YL0, ZL0); g2->SetLineColor(kRed); g2->SetLineWidth(3); h->Draw("box2 fb"); g2->Draw("same"); h->Draw("box2z fb same"); } int N=10; int Nc=3; Many3DHistograms(Nc,N);