Perspective View for 2D-Histograms

Hello,
I have some problems, when I try to switch the view of e.g. a “LEGO” representation of a TH2F to a perspective view. I try to do something like this:

  TH2F* h2 = new TH2F("h2","h2",50,-3,3,50,-3,3);
  TF2*  f2 = new TF2 ("f2","xygaus",-3,3,-3,3);
  Double_t params[] = {130,0,.5.,0,.5};
  f2->SetParameters(params);
  h2->FillRandom("f2",1000000);


  TCanvas* c1 = new TCanvas("c1","c1",640,480);
  h2->Draw("LEGO");

  c1->Draw();
  
  c1->GetView()->SetPerspective();
  c1->Update();
  c1->Draw();

After that the “LEGO” histogram is displayed perspectively, but the view angles are pretty bad. When I change the viewing angle with the mouse in the canvas, the first few changes usually work, but then ROOT crashes.

What is the recommended way to change the view of a TH2? representation to perspective view?

Cheers, J.

I suggest the GL alternative with:

[code]{
TH2F* h2 = new TH2F(“h2”,“h2”,50,-3,3,50,-3,3);
TF2* f2 = new TF2 (“f2”,“xygaus”,-3,3,-3,3);
Double_t params[] = {130,0,.5.,0,.5};
f2->SetParameters(params);
h2->FillRandom(“f2”,1000000);

gStyle->SetCanvasPreferGL();
TCanvas* c1 = new TCanvas(“c1”,“c1”,640,480);
h2->Draw(“LEGOgl”);
}
[/code]

Olivier will investigate the original problem once he will be back.

Rene

With some others histograms like the hpxpy one generated by $ROOTSYS/hsimple.C I do not get a crash after many rotations but the perspective view makes no sense.

It is stretched along the Z axis because Z goes from 0 to 180 and X and Z axis go from 0 to 1. Lego and Surface plot are not meant to be use in perspective view because in that case they do not appear Ortho-Normal.

Is there any reason why you would like to go that way ? In my sense it is not usuable (independently of the crash).