TH2D "Z" option in Draw


I’m wondering if it was possible fix the Z-axis range when drawing a TH2D in “COLZ” option. I basically wish to have the plotted values to be in between -1 and 1.

Essentially, here’s pseudo logic:

TH2D myHist;

for(all of the values){

now if I try myHist->getZAxis()->SetRange(-1,1); This has no effect whatsoever similarly SetRangeUSER(-1,1) doesn’t work either.

  1. if my values are above 1, or below -1, the z range stretches anyways. I fixed this by using if statements to set values<-1 as -1, and values>1 as 1, for the sake of the plot.
  2. if my values are below 1, and above 1, the z range shrinks, and different colours are assigned to each range.

I was wondering if there was a certain method to FIX z, colour range to be inbetween -1 to 1.

Thank you for your time.

Generally, the axis ranges for the the “bin contents” direction is not set with SetRange/SetRangeUser but with the SetMaximum/SetMinimum methods. So for a TH1 this would be the Y axis, but for a TH2 it would be the Z axis.

Try myhist->SetMaximum(1); myhist->SetMinimum(-1).

Thank you so much!

That was somewhat unexpected.