scikit-hep / histbook

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

"grid" histogram placement #21

Closed imandr closed 6 years ago

imandr commented 6 years ago

In addition to beside() and below(), it would be good to have grid() method to place a list of histograms in grid fashion, e.g:

grid(5, [hist1.step(), hist2.step(), ...]) - place histograms in Nx5 grid (N rows by 5 histograms) hist.grid(5, "param") - produce views with constant "param" and place them into Nx5 grid

jpivarski commented 6 years ago

Right. Thanks for the name! (PAW had "zones" and ROOT has "pads", neither of which is an intuitive name for me. "Grid" makes a lot of sense.)

I can do the first of these, but not the second. grid can be a standalone function that works like the beside and below standalone functions. But the methods that split data depend on functionality in Vega-Lite.

Notice how Vega-Lite renders histograms beside each other under a global axis title (e.g. "centrality bins") and labels (e.g. "0‒10%", "10‒30%", "30‒50%"). Each of those plots is, graphically, like a really big bin. If the values were spread in a grid like left-to-right, top-to-bottom reading order, then they couldn't be presented under a single axis. Graphically, one would need to put a legend in each re-stating the axis title ("centrality") and its current value. Physicists do this, it's a desired plot type, but not one with a convenience function in Vega-Lite.

So while the first case is something I can do, the second is a feature request for Vega-Lite. (The first makes it possible to manually build the second by constructing legends and such.)

jpivarski commented 6 years ago

Now we have grid:

>>> import numpy
>>> from histbook import *
>>> h = Hist(bin("x", 100, -5, 5), fill=numpy.random.normal(0, 1, 1000000))
>>> plot = h.step()
>>> grid(2, plot, plot, plot).vegascope()

vegascope

jpivarski commented 6 years ago

Somehow I missed checking this earlier, but overlay, beside, below, and grid are supposed to be composable (where logically possible). That's fixed now.

>>> import numpy
>>> from histbook import *
>>> h = Hist(bin("x", 10, -5, 5), fill=numpy.random.normal(0, 1, 1000000))
>>> below(h.step(), beside(h.line(), overlay(h.area(), h.marker()))).vegascope()

vegascope 1