Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use unbinned values as input to histplot #511

Open
JamesJieranShen opened this issue Aug 7, 2024 · 3 comments
Open

Use unbinned values as input to histplot #511

JamesJieranShen opened this issue Aug 7, 2024 · 3 comments

Comments

@JamesJieranShen
Copy link

Hello! Thanks for creating this great library (along with uproot, awkward, and many others!).

In my daily workflow, I have found many of the features provided by histplot to be extremely useful. However, I find myself using this as a replacement to plt.hist a lot when it comes to simple histograms. However, I would have to create this in two separate steps, first binning the values with np.histogram, and then feed the output to histplot. It would be great if I can directly pass an array of values and have histplot create a nice histogram, with the proper mplhep styling and features.

In short, I am looking for something like

hep.histplot(values, bins=100, range=(0, 200), yerr=True, color='k')

Does something like this already exist? If not, I think this would be a great feature to add. As far as I can tell, implementing something like this would simply involve calling np.histogram and then histplot.

@andrzejnovak
Copy link
Member

Hi @JamesJieranShen welcome! Can you explain why plt.hist doesn't suffice for your use-case? This library and histplot in particular was created to plot already existing histograms, such as the ones created via hist

@JamesJieranShen
Copy link
Author

There's many features provided by histplot that's not available in plt.hist. Off the top of my head the most useful ones include the automatic calculation and plotting of error bars as well as histograms with arbitrary bin width normalization. Plus, the default histtype of "fill" in plt.hist is also not ideal for many HEP-style plots (although this could just be a personal preference). Allowing all of the nice quality-of-life features provided by histplot to be quickly used just like plt.hist would be very useful.

@andrzejnovak
Copy link
Member

Thanks for the clarification. I am happy to hear you find histplot useful.

The main reason why something like that is not currently supported is because histplot([1,2,4,5,2,6,6,7]) or histplot([[1,1,1], [2,2,3], [2,3,4]]) get in interpreted as bin values or a set of bin values. Keeping the API sane while allowing a switch to treat such inputs as values to histogram seems a bit tricky.

However, one way I can see that this could work without being confusing to users would be a new mplhep.hist function that could implement the functionality you want (either as np.histogram or hist.Hist) under the hood and pass the results to histplot. I'd be happy to merge such functionality if you'd want to take a stab at a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants