Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Nov 6, 2018
2 parents 6e2af3c + 3478999 commit b6264df
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ The `stack <http://histbook.readthedocs.io/en/latest/plotting.html#histbook.vega
>>> r = "sqrt(x**2 + y**2)"
>>> phi = "arctan2(y, x)"
>>> hist.stack("arctan2(y, x)").area("sqrt(x**2+y**2)").to(canvas)
>>> hist.stack(phi).area(r).to(canvas)
.. image:: docs/source/intro-4.png

Expand Down
17 changes: 16 additions & 1 deletion histbook/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,23 @@ def root(self, *axis, **opts):
out.SetBinError(i, rooterrors[i])

elif len(binaxis) == 2:
xaxis = binaxis[0]
yaxis = binaxis[1]

if profile is None:
raise NotImplementedError("TH2")
out = ROOT.TH2D(name, title, xaxis.numbins, xaxis.low, xaxis.high, yaxis.numbins, yaxis.low, yaxis.high)

entries = numpy.zeros((xaxis.numbins + 2, yaxis.numbins + 2), dtype=numpy.float64)
entries[(0 if xaxis.underflow else 1) : (None if xaxis.overflow else -1), (0 if yaxis.underflow else 1) : (None if yaxis.overflow else -1)] = content["count()"][: (-1 if xaxis.nanflow else None), : (-1 if yaxis.nanflow else None)]
for idx, val in numpy.ndenumerate(entries):
out.SetBinContent(idx[0], idx[1], val)
out.SetEntries(entries.sum())

if "err(count())" in content.dtype.names:
errors = numpy.zeros(xaxis.numbins + 2, yaxis.numbins + 2, dtype=numpy.float64)
errors[(0 if xaxis.underflow else 1) : (None if xaxis.overflow else -1), (0 if yaxis.underflow else 1) : (None if yaxis.overflow else -1)] = content["err(count())"][: (-1 if xaxis.nanflow else None), : (-1 if yaxis.nanflow else None)]
for idx, val in numpy.ndenumerate(errors):
out.SetBinError(idx[0], idx[1], val)

else:
raise NotImplementedError("TProfile2D")
Expand Down

0 comments on commit b6264df

Please sign in to comment.