scikit-hep / histbook

Versatile, high-performance histogram toolkit for Numpy.
BSD 3-Clause "New" or "Revised" License
109 stars 9 forks source link

logarithmic scale on Y axis of Stack histogram #46

Open SiewYan opened 6 years ago

SiewYan commented 6 years ago

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!

jpivarski commented 6 years ago

step, area, line, and marker all take the same yscale="log" option for log scale.

SiewYan commented 6 years ago

Thanks for the suggestion, but if i set yscale="log" in area on the stack i got an empty histogram.

SiewYan commented 6 years ago

..... 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)

SiewYan commented 6 years ago
screen shot 2018-08-21 at 17 14 15
jpivarski commented 6 years ago

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).