histbook
histbook copied to clipboard
logarithmic scale on Y axis of Stack histogram
Hi, I am attempted to produce a stacked HEP histogram consists of various background's histograms. I would like to logarithmic scale my stack histogram but no such option in stack and area function. Its seem like the only option i have is to use step function (enabling logarithmic scale on y) on each background histogram (declare in group) before stacking them up. However, the return Plotable1d object from hist.step() does not have attribute stack, if i go by .stack().step(logy), stack() complain about only bar and area could be stacked. Is there a way to set logarithmic scale via .stack().area(logy) or any other equivalent method to achieve this?
Thanks!
step
, area
, line
, and marker
all take the same yscale="log"
option for log scale.
Thanks for the suggestion, but if i set yscale="log" in area on the stack i got an empty histogram.
..... ZZ,TT,etc are Hist obj
h1=Hist.group( ZZ=PROC['ZZ'].allvalues()[4], TT=PROC['TT'].allvalues()[4], WW=PROC['WW'].allvalues()[4], WZ=PROC['WZ'].allvalues()[4], DYJetsToLL=PROC['DYJetsToLL'].allvalues()[4], )
h1.stack("source",order=PROCLIST).area("mass",yscale="log").to(canvas)

Since there are no numbers on the vertical axis, I suspect that Vega-Lite is setting the scale range to something strange, like 0.1 through 0.9. As you can see in issue #37, Vega-Lite's log scale handling is immature— physicists use log scales a lot more than anybody else.
You can fix it by setting the scale manually. The yscale="log"
option is actually passing JSON through to Vega-Lite, so you can use all of the options in their documentation. I believe you want
https://vega.github.io/vega-lite/docs/scale.html#range
though it could be "domain," rather than "range." (I don't understand the distinction for this one-dimensional object.) You pass it through like this: yscale={"type": "log", "range": [0.1, 1000000]}
(or similar).