Skip to main content

Dataframe agnostic binscatter plots

TL;DR: Fast binscatter plots for all kinds of dataframes.

  • Built on the narwhals dataframe abstraction, so pandas, Polars, DuckDB, Dask, and PySpark inputs all work out of the box.
  • Uses plotly as graphics backend - because: (1) it's great (2) it uses narwhals as well, minimizing dependencies
  • Lightweight - little dependencies
  • Just works: by default picks the number of bins automatically via the DPI (Direct Plug-In) selector from Cattaneo et al. (2024) - no manual tuning

What are binscatter plots?

Binscatter plots group the x-axis into bins and plot average outcomes for each bin, giving a cleaner view of the relationship between two variables—possibly controlling for confounders. They show an estimate of the conditional mean, rather than all the underlying data as in a classical scatter plot.

Installation

pip install binscatter

Example

import plotly.express as px
from binscatter import binscatter

df = px.data.gapminder()
binscatter(df, "gdpPercap", "lifeExp")
Binscatter: GDP per capita vs Life Expectancy (DPI selector)

By default binscatter chooses bins via the DPI (Direct Plug-In) selector. Often we want more bins for a rawer look—use num_bins to specify the bin count:

binscatter(df, "gdpPercap", "lifeExp", num_bins=120)
Binscatter: GDP per capita vs Life Expectancy (120 bins)

See the rendered demo notebook for more examples. This package implements binscatter following Cattaneo et al. (2024).

Tests

  • Run the full backend matrix, including PySpark: make test
  • Use the faster run without PySpark: make ftest

Metadata

Release files for binscatter 0.4.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 binscatter 0.4.0
File Size Uploaded Provenance Actions
binscatter-0.4.0.tar.gz 34.4 kB With provenance Details for binscatter-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 71.6 kB

Release files / binscatter-0.4.0.tar.gz

Download URL binscatter-0.4.0.tar.gz
Size 34.4 kB
Tags Source
SHA-256 checksum
How to use checksums
8b73373fb396c4c1b4cfce7b68536ff12cb65845de1ed2421a67157ad0f98aff
BLAKE2b-256 checksum
How to use checksums
c50ee3e9c40eb299d504348672c0d188362770ccec83e343786e17509e089ec2
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 2, 2026.

Transparency log

Release files / binscatter-0.4.0-py3-none-any.whl

Download URL binscatter-0.4.0-py3-none-any.whl
Size 37.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c782af864926f04ea129c8c516614fe608cee56ced9462ab6cb05b3e4e2a5652
BLAKE2b-256 checksum
How to use checksums
082589b803c2843738bebcf75c9eb1f3faf1cdafc028190595e6016393424df9
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 2, 2026.

Transparency log

Security for binscatter 0.4.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.

Select from 2 files

Attestation for binscatter-0.4.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 2, 2026.

Transparency log

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.

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