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.10+
  • Numpy 1.25+
  • (optional) polars (1.0+), pandas (1.5+), 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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

physt-0.10.0.tar.gz (97.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

physt-0.10.0-py3-none-any.whl (107.4 kB view details)

Uploaded Python 3

File details

Details for the file physt-0.10.0.tar.gz.

File metadata

  • Download URL: physt-0.10.0.tar.gz
  • Upload date:
  • Size: 97.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for physt-0.10.0.tar.gz
Algorithm Hash digest
SHA256 97447cb59570e3c3c027b05da3b727efaec0493314b97d737f411577f88d03f8
MD5 0c78c45de4dfab09084cb65bacea9ece
BLAKE2b-256 b4138c47be239e5d9a876921a3e640f901751950e23d8f2e795b09231a36aa0e

See more details on using hashes here.

File details

Details for the file physt-0.10.0-py3-none-any.whl.

File metadata

  • Download URL: physt-0.10.0-py3-none-any.whl
  • Upload date:
  • Size: 107.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for physt-0.10.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7970042c6bedea463dece63ac5a3d4e112dde68e173b0dd52ab08a365293f5aa
MD5 8d8385f4dca8e61ea034e8f7d403c59d
BLAKE2b-256 2d65813da2b4a39e28f63cd8202cb93f68f6854c7eb15e0b322875a6a2fa32aa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.10.0 This release

2 files

0.9.0

2 files

0.8.6

2 files

0.8.5

2 files

0.8.4

2 files

0.8.2

2 files

0.8.1

2 files

0.8.0

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.5.3

1 file

0.5.2

1 file

0.5.1

1 file

0.5.0.1

1 file

0.5.0

1 file

0.4.12.2

1 file

0.4.12.1

1 file

0.4.12

1 file

0.4.10.1

1 file

0.4.10

1 file

0.4.9

1 file

0.4.8.3

1 file

0.4.8.2

1 file

0.4.8.1

1 file

0.4.8

1 file

0.4.7

1 file

0.4.6

1 file

0.4.5.1

1 file

0.4.5

1 file

0.4.4

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1

1 file

0.4.0

1 file

0.3.43.3

1 file

0.3.43.2

1 file

0.3.43.1

1 file

0.3.43

1 file

0.3.42

1 file

0.3.41

1 file

0.3.40.1

1 file

0.3.40

1 file

0.3.39.1

1 file

0.3.39

1 file

0.3.38

1 file

0.3.37

1 file

0.3.35

1 file

0.3.34

1 file

0.3.33

1 file

0.3.32

1 file

0.3.30

1 file

0.3.29

1 file

0.3.28.1

1 file

0.3.28

1 file

0.3.27

1 file

0.3.26

1 file

0.3.25

1 file

0.3.23

1 file

0.3.22.1

1 file

0.3.22

1 file

0.3.21

1 file

0.3.20

1 file

0.3.19

1 file

0.3.18

1 file

0.3.17

1 file

0.3.16

1 file

0.3.15

1 file

0.3.14

1 file

0.3.13

1 file

0.3.12

1 file

0.3.11

1 file

0.3.10

1 file

0.3.8.1

1 file

0.3.8

1 file

0.3.7.1

1 file

0.3.6

1 file

0.3.5

1 file

0.3.4

1 file

0.3.3

1 file

0.3.2.1

1 file

0.3.1

1 file

0.3

1 file

0.2.101

1 file

0.2.2

1 file

0.2.1

1 file

0.2

1 file

0.1.0

1 file

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