Skip to main content

physt Physt logo

P(i/y)thon h(i/y)stograms. Inspired (and based on) numpy.histogram, but designed for humans(TM) on steroids(TM).

Create rich histogram objects from numpy or dask arrays, from pandas and polars series/dataframes, from xarray datasets and a few more types of objects. Manipulate them with ease, plot them with matplotlib, vega or plotly.

In short, whatever you want to do with histograms, physt aims to be on your side.

ReadTheDocs Join the chat at https://gitter.im/physt/Lobby PyPI downloads PyPI version Anaconda-Server Badge Anaconda-Server Badge Code style: black

See it in action

With uv installed, you can run the following command without needing to install anything to see some examples in action:

uv run --with "physt[terminal]>=0.8.3" -m physt.examples

Command-line interface (experimental)

You can run (and install) physt as a command-line application to quickly analyse data files. This functionality is currently in development.

uv run physt h1 "src/physt/examples/munros.csv" -c height  -p -n 10

For more information, use the --help flag.

Simple example

from physt import h1

# Create the sample
heights = [160, 155, 156, 198, 177, 168, 191, 183, 184, 179, 178, 172, 173, 175,
           172, 177, 176, 175, 174, 173, 174, 175, 177, 169, 168, 164, 175, 188,
           178, 174, 173, 181, 185, 166, 162, 163, 171, 165, 180, 189, 166, 163,
           172, 173, 174, 183, 184, 161, 162, 168, 169, 174, 176, 170, 169, 165]

hist = h1(heights, 10)           # <--- get the histogram data
hist << 190                      # <--- add a forgotten value
hist.plot()                      # <--- and plot it

Heights plot

2D example

from physt import h2
import seaborn as sns

iris = sns.load_dataset('iris')
iris_hist = h2(iris["sepal_length"], iris["sepal_width"], "pretty", bin_count=[12, 7], name="Iris")
iris_hist.plot(show_zero=False, cmap="gray_r", show_values=True);

Iris 2D plot

3D directional example

import numpy as np
from physt import special_histograms

# Generate some sample data
data = np.empty((1000, 3))
data[:,0] = np.random.normal(0, 1, 1000)
data[:,1] = np.random.normal(0, 1.3, 1000)
data[:,2] = np.random.normal(1, .6, 1000)

# Get histogram data (in spherical coordinates)
h = special_histograms.spherical(data)

# And plot its projection on a globe
h.projection("theta", "phi").plot.globe_map(density=True, figsize=(7, 7), cmap="rainbow")

Directional 3D plot

See more in docstring's and notebooks:

Installation

Using pip:

pip install physt

or conda:

conda install -c janpipek physt

Features

Implemented

  • 1D histograms
  • 2D histograms
  • ND histograms
  • Some special histograms
    • 2D polar coordinates (with plotting)
    • 3D spherical / cylindrical coordinates (beta)
  • Adaptive rebinning for on-line filling of unknown data (beta)
  • Non-consecutive bins
  • Memory-effective histogramming of dask arrays (beta)
  • Understands any numpy-array-like object
  • Keep underflow / overflow / missed bins
  • Basic numeric operations (* / + -)
  • Items / slice selection (including mask arrays)
  • Add new values (fill, fill_n)
  • Cumulative values, densities
  • Simple statistics for original data (mean, std, sem) - only for 1D histograms
  • Plotting with several backends
    • matplotlib (static plots with many options)
    • vega (interactive plots, broken, help wanted!)
    • folium (experimental for geo-data)
    • plotly (very basic, help wanted!)
    • ascii (experimental)
  • Algorithms for optimized binning
    • pretty (nice rounded bin edges)
    • mathematical (statistical, quantile-based, geometrical, ...)
  • IO, conversions
    • I/O JSON
    • I/O xarray.DataSet (experimental)
    • O ROOT file (experimental)
    • O pandas.DataFrame (basic)

Planned

  • Rebinning
    • using reference to original data?
    • merging bins
  • Statistics (based on original data)?
  • Stacked histograms (with names)
  • Potentially holoviews plotting backend (instead of the discontinued bokeh one)

Not planned

  • Kernel density estimates - use your favourite statistics package (like seaborn)
  • Rebinning using interpolation - it should be trivial to use rebin (https://github.com/jhykes/rebin) with physt

Rationale (for both): physt is dumb, but precise.

Dependencies

  • Python 3.11+
  • Numpy 2.0+
  • (optional) polars (1.0+), pandas (2.0+), dask, xarray - if you want to histogram those
  • (optional) matplotlib - simple visualization
  • (optional) xarray - I/O
  • (optional) astropy - additional binning algorithms
  • (optional) folium - map plotting
  • (optional) rich - console output including plots
  • (testing) pytest
  • (docs) sphinx, sphinx_rtd_theme, ipython

Publicity

Talk at PyData Berlin 2018:

Contribution

I am looking for anyone interested in using / developing physt. You can contribute by reporting errors, implementing missing features and suggest new one.

Thanks to:

Patches:

Alternatives and inspirations

Metadata

Release files for physt 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for physt 0.11.0
File Size Uploaded Provenance Actions
physt-0.11.0.tar.gz 97.7 kB Without provenance Details for physt-0.11.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for physt 0.11.0
File Interpreter ABI Platform Actions
physt-0.11.0-py3-none-any.whl Python 3 none any Details for physt-0.11.0-py3-none-any.whl

Total release size: 205.5 kB

Release files / physt-0.11.0.tar.gz

Download URL physt-0.11.0.tar.gz
Size 97.7 kB
Tags Source
SHA-256 checksum
How to use checksums
df29c73be90c06ad29909b2ddd31933099962cec68db8ee64f12921f4afc558b
BLAKE2b-256 checksum
How to use checksums
91a6fd4da3ba6d83b9747713fd83bf9c9131c840389c3039996e3395c035421d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0

Release files / physt-0.11.0-py3-none-any.whl

Download URL physt-0.11.0-py3-none-any.whl
Size 107.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d001c037f2fb99dc7c9beb6cc71161746238e4aee4e5152dc7fe394a17f13981
BLAKE2b-256 checksum
How to use checksums
4e80f2dc9f636036a08053c5a0a2bbaeb5e66277416f3ffd584c5bf99c4bd999
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.0

Security for physt 0.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page