Cannot plot boost-histogram histogram when using a storage
See original GitHub issueUsing an accumulator storage in histogram when plotting returns an error. This makes it very difficult to plot sumw2 errors
code:
import mplhep as hep
import boost_histogram as bh
# Make 1-d histogram with 5 logarithmic bins from 1e0 to 1e5
h = bh.Histogram(
bh.axis.Regular(5, 1e0, 1e5, metadata="x", transform=bh.axis.transform.log),
storage=bh.storage.Weight(),
)
# Fill histogram with numbers
x = (2e0, 2e1, 2e2, 2e3, 2e4)
h.fill(x, weight=2)
hep.histplot(h)
error:
File "C:\Users\user\anaconda3\envs\myenv\lib\site-packages\mplhep\plot.py", line 132, in histplot
h = np.asarray(h).astype(float)
TypeError: Cannot cast array from dtype([('value', '<f8'), ('variance', '<f8')]) to dtype('float64') according to the rule 'unsafe'
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Quickstart — boost-histogram docs
You can use hist. values() to get a NumPy array from any histogram. You can get the variances with hist. variances() , though...
Read more >boost-histogram and hist - CERN Indico
Resembles the original Boost.Histogram where possible, with changes where needed for Python performance and idioms. C++. #include <boost/ ...
Read more >Writing a boost-histogram to a root file created in uproot
I am currently trying to read in a ROOT tree with uproot, book and fill histograms with boost-histogram and write these back out...
Read more >Boost-histogram: High-Performance Histograms as Objects ...
Unlike arrays and tables, histograms in Python have usually been denied theirown object, and have been represented as a single operation ...
Read more >Boost Histogram for Python - A Quick Start - Lovely Buggies
Matplotlib is a Python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

This is one of the reasons we need https://github.com/scikit-hep/boost-histogram/issues/423 - I’m hoping to make progress on that issue next week, @HDembinski had some good suggestions that I can build a new proposal iteration on.
@KeanuGh seems fixed (I’ve added
plt.semilogx()to your example)