Histogram with side by side bars instead of overlaid with alpha

Could do something like this yourself:

import numpy as np

hist1, bins = np.histogram(np.random.randn(100), range=(-5, 5), bins=21)
hist2, bins = np.histogram(np.random.randn(100)-1, range=(-5, 5), bins=21)

def stacked_hists(hist1, hist2, bins):
    diff = np.diff(bins)/2.
    bins = np.insert(bins, np.arange(1, len(bins)), bins[:-1]+diff)
    hist1 = np.insert(hist1, np.arange(0, len(hist1)), np.zeros(len(hist1)))
    hist2 = np.insert(hist2, np.arange(1, len(hist2)+1), np.zeros(len(hist2)))
    return hv.Histogram((bins, hist1)) * hv.Histogram((bins, hist2))

stacked_hists(hist1, hist2, bins)

Screen Shot 2020-07-24 at 12.09.07 AM

Also not opposed to adding something like this to the histogram operation though.

2 Likes