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);