scikit-hep / hist

Histogramming for analysis powered by boost-histogram
https://hist.readthedocs.io
BSD 3-Clause "New" or "Revised" License
128 stars 25 forks source link

[FEATURE] hist.plot legend automatically #558

Open andrzejnovak opened 10 months ago

andrzejnovak commented 10 months ago

Currently running

h = hist.new.Reg(100, 0, 10, label="X").StrCat([], label="Sample", growth=True).Weight()\
        .fill(np.random.normal(5, 1, int(1e5)), np.random.choice(list("ABCDEF"), int(1e5)))
h.plot1d(stack=True, histtype='fill', sort='label');
plt.legend()
hep.cms.label();

doesn't automatically plot the legend, meaning that when user triggers this themselves the "Sample" label won't appear automatically because there is nowhere to store it within the plot1d method without calling legend.

image

Should we include the legend automatically so that the legend title can be read from the axis info? The downside the user having slightly worse access to the legend object compared to they themselves running leg = plt.legend()