question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot plot boost-histogram histogram when using a storage

See original GitHub issue

Using 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:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
henryiiicommented, Oct 17, 2020

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.

0reactions
andrzejnovakcommented, May 22, 2021

@KeanuGh seems fixed (I’ve added plt.semilogx() to your example) image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found