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()); yc=N*(gRandom->Rndm()); h->Fill(xc,yc,zc); } } ZOffset3D(h, 100); TRandom *r = new TRandom(); int xx0, yy0, zz0; // To make the straight line TGraph2D *dt0 = new TGraph2D(); int x1 = N*(r->Rndm()); int y1 = N*(r->Rndm()); int x2 = N*(r->Rndm()); int y2 = N*(r->Rndm()); int z1=Z[0]-10; int z2=Z[Nc-1]+10; dt0->SetPoint(0,x1,y1,z1); dt0->SetPoint(1,x2,y2,z2); dt0->SetMarkerStyle(1); dt0->SetLineColor(kRed); dt0->SetLineWidth(10); int T=h->GetMaximum(); NewPalette(T, 100,19,12); //greys, works great h->Draw("box2 fb"); dt0->Draw("p line same"); h->Draw("box2z fb same"); } int N=10; int Nc=3; Many3DHistograms(Nc,N);