multihist
===========
.. image:: https://github.com/JelleAalbers/multihist/actions/workflows/tests.yml/badge.svg
:target: https://github.com/JelleAalbers/multihist/actions/workflows/tests.yml
`https://github.com/JelleAalbers/multihist`
Thin wrapper around numpy's histogram and histogramdd.
Numpy has great histogram functions, which return (histogram, bin_edges) tuples. This package wraps these in a class
with methods for adding new data to existing histograms, take averages, projecting, etc.
For 1-dimensional histograms you can access cumulative and density information, as well as basic statistics (mean and std).
For d-dimensional histograms you can name the axes, and refer to them by their names when projecting / summing / averaging.
**NB**: For a faster and richer histogram package, check out `hist <https://github.com/scikit-hep/hist>`_ from scikit-hep. Alternatively, look at its parent library `boost-histogram <https://github.com/scikit-hep/boost-histogram>`_, which has `numpy-compatible features <https://boost-histogram.readthedocs.io/en/latest/usage/numpy.html>`_. Multihist was created back in 2015, long before those libraries existed.
Synopsis::
# Create histograms just like from numpy...
m = Hist1d([0, 3, 1, 6, 2, 9], bins=3)
# ...or add data incrementally:
m = Hist1d(bins=100, range=(-3, 4))
m.add(np.random.normal(0, 0.5, 10**4))
m.add(np.random.normal(2, 0.2, 10**3))
# Get the data back out:
print(m.histogram, m.bin_edges)
# Access derived quantities like bin_centers, normalized_histogram, density, cumulative_density, mean, std
plt.plot(m.bin_centers, m.normalized_histogram, label="Normalized histogram", drawstyle='steps')
plt.plot(m.bin_centers, m.density, label="Empirical PDF", drawstyle='steps')
plt.plot(m.bin_centers, m.cumulative_density, label="Empirical CDF", drawstyle='steps')
plt.title("Estimated mean %0.2f, estimated std %0.2f" % (m.mean, m.std))
plt.legend(loc='best')
plt.show()
# Slicing and arithmetic behave just like ordinary ndarrays
print("The fourth bin has %d entries" % m[3])
m[1:4] += 4 + 2 * m[-27:-24]
print("Now it has %d entries" % m[3])
# Of course I couldn't resist adding a canned plotting function:
m.plot()
plt.show()
# Create and show a 2d histogram. Axis names are optional.
m2 = Histdd(bins=100, range=[[-5, 3], [-3, 5]], axis_names=['x', 'y'])
m2.add(np.random.normal(1, 1, 10**6), np.random.normal(1, 1, 10**6))
m2.add(np.random.normal(-2, 1, 10**6), np.random.normal(2, 1, 10**6))
m2.plot()
plt.show()
# x and y projections return Hist1d objects
m2.projection('x').plot(label='x projection')
m2.projection(1).plot(label='y projection')
plt.legend()
plt.show()
History
-------
------------------
0.6.5 (2022-01-26)
------------------
* 'model' option for error bars, showing Poisson quantiles (#14)
* Fix vmin/vmax for matplotlib >3.3, resume CI tests (#15)
* Hist1d.data_for_plot returns numbers used in error calculation
------------------
0.6.4 (2021-01-17)
------------------
* Prevent object array creation (#12)
------------------
0.6.3 (2020-01-22)
------------------
* Feldman-Cousins errors for Hist1d.plot (#10)
------------------
0.6.2 (2020-01-15)
------------------
* Fix rebinning for empty histograms (#9)
------------------
0.6.1 (2019-12-05)
------------------
* Fixes for #7 (#8)
------------------
0.6.0 (2019-06-30)
------------------
* Correct step plotting at edges, other plotting fixes
* Histogram numpy structured arrays
* Fix deprecation warnings (#6)
* `lookup_hist`
* `.max()` and `.min()` methods
* percentile support for higher-dimensional histograms
* Improve Hist1d.get_random (also randomize in bin)
------------------
0.5.4 (2017-09-20)
------------------
* Fix issue with input from dask
------------------
0.5.3 (2017-09-18)
------------------
* Fix python 2 support
------------------
0.5.2 (2017-08-08)
------------------
* Fix colorbar arguments to Histdd.plot (#4)
* percentile for Hist1d
* rebin method for Histdd (experimental)
------------------
0.5.1 (2017-03-22)
------------------
* get_random for Histdd no longer just returns bin centers (Hist1d does stil...)
* lookup for Hist1d. When will I finally merge the classes...
------------------
0.5.0 (2016-10-07)
------------------
* pandas.DataFrame and dask.dataframe support
* dimensions option to Histdd to init axis_names and bin_centers at once
------------------
0.4.3 (2016-10-03)
------------------
* Remove matplotlib requirement (still required for plotting features)
------------------
0.4.2 (2016-08-10)
------------------
* Fix small bug for >=3 d histograms
------------------
0.4.1 (2016-17-14)
------------------
* get_random and lookup for Histdd. Not really tested yet.
------------------
0.4.0 (2016-02-05)
------------------
* .std function for Histdd
* Fix off-by-one errors
------------------
0.3.0 (2015-09-28)
------------------
* Several new histdd functions: cumulate, normalize, percentile...
* Python 2 compatibility
------------------
0.2.1 (2015-08-18)
------------------
* Histdd functions sum, slice, average now also work
----------------
0.2 (2015-08-06)
----------------
* Multidimensional histograms
* Axes naming
--------------------
0.1.1-4 (2015-08-04)
--------------------
Correct various rookie mistakes in packaging...
Hey, it's my first pypi package!
----------------
0.1 (2015-08-04)
----------------
Initial release
* Hist1d, Hist2d
* Basic test suite
* Basic readme
Raw data
{
"_id": null,
"home_page": "https://github.com/jelleaalbers/multihist",
"name": "multihist",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "multihist,histogram",
"author": "Jelle Aalbers",
"author_email": "j.aalbers@uva.nl",
"download_url": "https://files.pythonhosted.org/packages/73/df/bcbe4c72f03c4cb0f550329d6148628fe1f81f7da95d3c2afb867fb437f4/multihist-0.6.5.tar.gz",
"platform": "",
"description": "multihist\n===========\n\n.. image:: https://github.com/JelleAalbers/multihist/actions/workflows/tests.yml/badge.svg\n :target: https://github.com/JelleAalbers/multihist/actions/workflows/tests.yml\n\n`https://github.com/JelleAalbers/multihist`\n\nThin wrapper around numpy's histogram and histogramdd.\n\nNumpy has great histogram functions, which return (histogram, bin_edges) tuples. This package wraps these in a class\nwith methods for adding new data to existing histograms, take averages, projecting, etc.\n\nFor 1-dimensional histograms you can access cumulative and density information, as well as basic statistics (mean and std).\nFor d-dimensional histograms you can name the axes, and refer to them by their names when projecting / summing / averaging.\n\n**NB**: For a faster and richer histogram package, check out `hist <https://github.com/scikit-hep/hist>`_ from scikit-hep. Alternatively, look at its parent library `boost-histogram <https://github.com/scikit-hep/boost-histogram>`_, which has `numpy-compatible features <https://boost-histogram.readthedocs.io/en/latest/usage/numpy.html>`_. Multihist was created back in 2015, long before those libraries existed.\n\nSynopsis::\n\n # Create histograms just like from numpy...\n m = Hist1d([0, 3, 1, 6, 2, 9], bins=3)\n\n # ...or add data incrementally:\n m = Hist1d(bins=100, range=(-3, 4))\n m.add(np.random.normal(0, 0.5, 10**4))\n m.add(np.random.normal(2, 0.2, 10**3))\n\n # Get the data back out:\n print(m.histogram, m.bin_edges)\n\n # Access derived quantities like bin_centers, normalized_histogram, density, cumulative_density, mean, std\n plt.plot(m.bin_centers, m.normalized_histogram, label=\"Normalized histogram\", drawstyle='steps')\n plt.plot(m.bin_centers, m.density, label=\"Empirical PDF\", drawstyle='steps')\n plt.plot(m.bin_centers, m.cumulative_density, label=\"Empirical CDF\", drawstyle='steps')\n plt.title(\"Estimated mean %0.2f, estimated std %0.2f\" % (m.mean, m.std))\n plt.legend(loc='best')\n plt.show()\n\n # Slicing and arithmetic behave just like ordinary ndarrays\n print(\"The fourth bin has %d entries\" % m[3])\n m[1:4] += 4 + 2 * m[-27:-24]\n print(\"Now it has %d entries\" % m[3])\n\n # Of course I couldn't resist adding a canned plotting function:\n m.plot()\n plt.show()\n\n # Create and show a 2d histogram. Axis names are optional.\n m2 = Histdd(bins=100, range=[[-5, 3], [-3, 5]], axis_names=['x', 'y'])\n m2.add(np.random.normal(1, 1, 10**6), np.random.normal(1, 1, 10**6))\n m2.add(np.random.normal(-2, 1, 10**6), np.random.normal(2, 1, 10**6))\n m2.plot()\n plt.show()\n\n # x and y projections return Hist1d objects\n m2.projection('x').plot(label='x projection')\n m2.projection(1).plot(label='y projection')\n plt.legend()\n plt.show()\n\n\n\n\nHistory\n-------\n\n------------------\n0.6.5 (2022-01-26)\n------------------\n* 'model' option for error bars, showing Poisson quantiles (#14)\n* Fix vmin/vmax for matplotlib >3.3, resume CI tests (#15)\n* Hist1d.data_for_plot returns numbers used in error calculation\n\n------------------\n0.6.4 (2021-01-17)\n------------------\n* Prevent object array creation (#12)\n\n------------------\n0.6.3 (2020-01-22)\n------------------\n* Feldman-Cousins errors for Hist1d.plot (#10)\n\n------------------\n0.6.2 (2020-01-15)\n------------------\n* Fix rebinning for empty histograms (#9)\n\n------------------\n0.6.1 (2019-12-05)\n------------------\n* Fixes for #7 (#8)\n\n------------------\n0.6.0 (2019-06-30)\n------------------\n* Correct step plotting at edges, other plotting fixes\n* Histogram numpy structured arrays\n* Fix deprecation warnings (#6)\n* `lookup_hist`\n* `.max()` and `.min()` methods\n* percentile support for higher-dimensional histograms\n* Improve Hist1d.get_random (also randomize in bin)\n\n------------------\n0.5.4 (2017-09-20)\n------------------\n* Fix issue with input from dask\n\n------------------\n0.5.3 (2017-09-18)\n------------------\n* Fix python 2 support\n\n------------------\n0.5.2 (2017-08-08)\n------------------\n* Fix colorbar arguments to Histdd.plot (#4)\n* percentile for Hist1d\n* rebin method for Histdd (experimental)\n\n------------------\n0.5.1 (2017-03-22)\n------------------\n* get_random for Histdd no longer just returns bin centers (Hist1d does stil...)\n* lookup for Hist1d. When will I finally merge the classes...\n\n------------------\n0.5.0 (2016-10-07)\n------------------\n* pandas.DataFrame and dask.dataframe support\n* dimensions option to Histdd to init axis_names and bin_centers at once\n\n------------------\n0.4.3 (2016-10-03)\n------------------\n* Remove matplotlib requirement (still required for plotting features)\n\n------------------\n0.4.2 (2016-08-10)\n------------------\n* Fix small bug for >=3 d histograms\n\n------------------\n0.4.1 (2016-17-14)\n------------------\n* get_random and lookup for Histdd. Not really tested yet.\n\n------------------\n0.4.0 (2016-02-05)\n------------------\n* .std function for Histdd\n* Fix off-by-one errors\n\n------------------\n0.3.0 (2015-09-28)\n------------------\n* Several new histdd functions: cumulate, normalize, percentile...\n* Python 2 compatibility\n\n------------------\n0.2.1 (2015-08-18)\n------------------\n* Histdd functions sum, slice, average now also work\n\n----------------\n0.2 (2015-08-06)\n----------------\n* Multidimensional histograms\n* Axes naming\n\n--------------------\n0.1.1-4 (2015-08-04)\n--------------------\nCorrect various rookie mistakes in packaging...\nHey, it's my first pypi package!\n\n----------------\n0.1 (2015-08-04)\n----------------\nInitial release\n\n* Hist1d, Hist2d\n* Basic test suite\n* Basic readme\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Convenience wrappers around numpy histograms",
"version": "0.6.5",
"split_keywords": [
"multihist",
"histogram"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "57c22febb099929db74cd1cd5951fd86",
"sha256": "f5fcce0712706c99a462cb19580fc37ffc1a6665e490a841705ea1b9d029edf9"
},
"downloads": -1,
"filename": "multihist-0.6.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "57c22febb099929db74cd1cd5951fd86",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 14595,
"upload_time": "2022-01-27T04:09:05",
"upload_time_iso_8601": "2022-01-27T04:09:05.303189Z",
"url": "https://files.pythonhosted.org/packages/8b/81/6a9848217ca43ef6930c9ec8abde2e0d8a40c4078875cb26799b185ef82f/multihist-0.6.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"md5": "e411fd3cb227d2bc0066dcb1248c280f",
"sha256": "020e88693228d50b23b77fd59f2e998de8b1d7517f5697cec4d4616d7d011cdd"
},
"downloads": -1,
"filename": "multihist-0.6.5.tar.gz",
"has_sig": false,
"md5_digest": "e411fd3cb227d2bc0066dcb1248c280f",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 16661,
"upload_time": "2022-01-27T04:09:07",
"upload_time_iso_8601": "2022-01-27T04:09:07.219721Z",
"url": "https://files.pythonhosted.org/packages/73/df/bcbe4c72f03c4cb0f550329d6148628fe1f81f7da95d3c2afb867fb437f4/multihist-0.6.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-01-27 04:09:07",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "jelleaalbers",
"github_project": "multihist",
"travis_ci": true,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "numpy",
"specs": []
}
],
"lcname": "multihist"
}