Add .bin_centers to BinnedStatisticResult (and possible API change)
See original GitHub issueIs your feature request related to a problem? Please describe.
-
I used
binned_statisticandbinned_statistic_2dquite a bit, but often need to get the bin centers out to plot (statistic) vs. (bin centers). So, in 1D, I always end up typing this:stat = binned_statistic(…) bin_ctr = 0.5 * (stat.bin_edges[1:] + stat.bin_edges[:-1])
-
As a separate but related point, in 1D and DD, the bin edges can be retrieved with
stat.bin_edges, but in 2D, the bin edges are provided separately as.x_edgesand.y_edges. I think this makes the API less consistent, and would propose thatBinnedStatistic2dResultshould instead have.bin_edges.
Describe the solution you’d like
-
I propose either adding a new attribute to the
BinnedStatisticResultNamedTuple’s to store the bin centers, or promoting these into small classes and adding a property that computes the bin centers on the fly from the bin edges. -
I propose deprecating
.x_edgesand.y_edgesinBinnedStatistic2dResultand moving to.bin_edges.
Thanks for reading!
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (7 by maintainers)

Top Related StackOverflow Question
Note that we already have
_make_tuple_bunch, which allows us to convert the output to an object with as many fields as we want but still works like a tuple (with the original elements) if it is unpacked.The result class could implement
__len__()and__getitem__()to emulate the legacy tuple items while still adding more additional attributes that are only accessible as attributes.One other option for bin centers might be to add a utility function that converts bin edges to the
(centers, widths)representation. After the discussion about bin centers on numpy/numpy#13194, it seems that the manual conversion is more of a burden for people than I would have expected.