Cannot SetMaxDigits on z-axis

The TAxis::SetMaxDigits function does not appear to work on the z-axis of a 2D histogram. I cannot see an effect, in any event. Reproducer follows.


df = ROOT.RDataFrame(1000).Define('rand1', 'gRandom->Uniform(0, 0.001)').Define('rand2', 'gRandom->Uniform(0, 0.001)')
h = df.Histo2D(('h', 'h', 10, 0, 0.001, 10, 0, 0.001), 'rand1', 'rand2')
h.Scale(0.001)
h.Draw('colz')

Notice that the y-axis ranges from “0” to “0.001” and the z-axis from “0.004” to “0.018”

h.GetYaxis().SetMaxDigits(1)
h.GetZaxis().SetMaxDigits(1)

Notice that the y-axis now ranges from “0” to “1” x10-3, while the z-axis remains unchanged.

ROOT.TGaxis.SetMaxDigits(1)

Notice that the y- and z-axes have the adjusted range format, while the x-axis remains unchanged.


ROOT Version: master
Platform: macOS
Compiler: Not Provided


I think the problem is that drawing with colz you don’t get a 3D plot, and the colour scale is a TPaletteAxis (not a TAxis), which does not have SetMaxDigits, as well as other TAxis methods. If you draw with “lego2”, for instance, you get a z-axis on which you can use SetMaxDigits, etc.
Edit: you can actually get the axis from TPalette:

(...)
h.Draw('colz')
palette = h.GetListOfFunctions().FindObject("palette")
zax = palette.GetAxis()
zax.SetMaxDigits(1)

then update the Pad or canvas.

yes, the axis pointer returned by GetZaxis() is not the same as the one used in the palette:

root [0] hpxpy->Draw("colz")
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
root [1] hpxpy->GetZaxis()
(TAxis *) 0x7fb867275628
root [2] auto palette = (TPaletteAxis *)hpxpy->GetListOfFunctions()->FindObject("palette");
root [3] cout << palette->GetAxis() << endl;
0x7fb814d14360

Thank you, @couet and @dastudillo, for the explanation. This behavior is not intuitive, as one expects "COLZ" to simply be a way to represent the z-axis, but I imagine it would be quite a lift to change. Perhaps such a change could be incorporated in ROOT 7; I’ve submitted a JIRA feature request here.

Thanks ! Looking at it.

This is now fixed in master.

hpxpy->GetZaxis()->SetMaxDigits(1)
hpxpy->Scale(0.0001)
hpxpy->Draw("colz")

1 Like

Thank you much, @couet!

Actually the fix has side effects in stressGraphics. I will revert until I found where it comes from. It should be fine soon.

It is now properly fixed. Sorry for the delay.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.