Dataframe agnostic binscatter plots
TL;DR: Fast binscatter plots with automatic bin selection for all kinds of dataframes
- Handles pandas, Polars, DuckDB, Dask, and PySpark via
narwhals - Supports covariate adjustment (including high-dimensional categoricals) and confidence intervals
- Interactive plots via
plotly - Implementation follows Cattaneo et al. (2024)
What are binscatter plots?
Binscatter plots group the x-axis into bins and plot the average y value for each bin, giving a cleaner view of the relationship between two variables. They estimate the conditional mean rather than displaying all the underlying observations, and can also adjust for covariates and provide statistical inference.
Installation
pip install binscatter
Example
import pandas as pd
from binscatter import binscatter
df = pd.read_csv("data/nhanes_age_bp.csv")
binscatter(df, "age", "systolic_bp")
binscatter automatically chooses the number of bins with the DPI selector. For
covariate adjustment, confidence intervals, alternative bin selectors, polynomial
overlays, and dataframe-backend examples, see the
rendered demo notebook.
High-dimensional categorical controls
binscatter handles high-dimensional categorical controls efficiently with the
method of alternating projections (MAP), without building a large one-hot matrix.
Example timings for 5,000 pandas rows and 10 bins:
| categories | binscatter |
explicit one-hot | speedup |
|---|---|---|---|
| 10 | ~0.009s | ~0.017s | ~2× |
| 25 | ~0.008s | ~0.064s | ~8× |
| 50 | ~0.008s | ~0.28s | ~36× |
Reference environment: MacBook Air (Apple M1, 8 CPU cores, 16 GB RAM), macOS
15.6.1 arm64, Python 3.11.9, and pandas 3.0.5. The values are medians of three
calls from make benchmark-fe-fast, run locally on 10 August 2026; they are
comparative measurements, not performance guarantees for other machines.
make benchmark-fe-fast # short suite
make benchmark-fe # up to 1M rows and 50K levels
Tests
- Check a representative sample while working:
make test-fast(~18s) - Run the whole suite without PySpark:
make test - Run the full backend matrix, including PySpark:
make test-spark
Metadata
Release files for binscatter 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| binscatter-0.5.0.tar.gz | 47.5 kB | With provenance | Details for binscatter-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| binscatter-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for binscatter-0.5.0-py3-none-any.whl |
Total release size: 98.2 kB
Release files / binscatter-0.5.0.tar.gz
| Download URL | binscatter-0.5.0.tar.gz |
|---|---|
| Size | 47.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ba6739cf6c9f14f8c94e940496542512988d08b8247f0770b2fa95cf89a470e5
|
|
BLAKE2b-256 checksum How to use checksums |
81d49b196e1052faea3c6e516e6ddca84e2069ddedd6749144e3892ea38cbd23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.
Transparency logRelease files / binscatter-0.5.0-py3-none-any.whl
| Download URL | binscatter-0.5.0-py3-none-any.whl |
|---|---|
| Size | 50.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1097715f5bc0ae246089e8af6e7d2b7f8c57931e0932ede0600b0736fffb7976
|
|
BLAKE2b-256 checksum How to use checksums |
e0d07ab7d00797969fcfbb9783c40cde01f8b7ff781902ddd14f10878cb34841
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.
Transparency logSecurity for binscatter 0.5.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for binscatter-0.5.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 16, 2026.
Transparency logA 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.