Dear experts,
I just ran across the following. When drawing a TGraph, if the strings on the vertical axis become too long (looks like more than eight characters, including the dot) then setting TStyle::SetStripDecimals(1) no longer works.
Please see the below piece of code which can produce two output figures (cases oops' and
not oops’), both attached.
from ROOT import gStyle
from ROOT import TCanvas
from ROOT import TGraph
if __name__ == "__main__":
# Do not strip decimal zeros off the axis labels.
gStyle.SetStripDecimals(False)
gStyle.SetPadLeftMargin(.15)
gStyle.SetPadBottomMargin(.12)
graph_freq = TGraph()
# Use this to toggle the problem.
oops = True
if oops:
graph_freq.SetPoint(0, 933., 40078879.) # <-- y-value more than 7 characters
graph_freq.SetPoint(1, 934., 40078966.) # <-- y-value more than 7 characters
else:
graph_freq.SetPoint(0, 933., 4007887.) # <-- y-value only 7 characters
graph_freq.SetPoint(1, 934., 4007896.) # <-- y-value only 7 characters
canvas = TCanvas("canvas")
graph_freq.Draw("A*")
canvas.Print("test_strip_decimals.eps")
# Done
The same thing happens in v5.18/00 and the current SVN head, in my case on a MacBook and from PyROOT but I don’t think those are relevant.
Was this a choice? It seems a bit arbitrary. Can I work around this?
Cheers,
Jeroen
test_strip_decimals_not_oops.pdf (3.3 KB)
test_strip_decimals_oops.pdf (3.29 KB)