Skip to main content

Cross-backend binscatter plots.

Project description

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 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

Project details


Download files

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

Source Distribution

binscatter-0.3.1.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

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

binscatter-0.3.1-py3-none-any.whl (24.2 kB view details)

Uploaded Python 3

File details

Details for the file binscatter-0.3.1.tar.gz.

File metadata

  • Download URL: binscatter-0.3.1.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for binscatter-0.3.1.tar.gz
Algorithm Hash digest
SHA256 27624f325d3518c608273e235450c464ab23b48e4e42fb3d445a3689f15c1d54
MD5 97bf13532d7041367788fd20ed9beb4d
BLAKE2b-256 736d1997a99129bea6f281db640d36e2d449c5b0e545cf3a747c92556f9a6a4b

See more details on using hashes here.

File details

Details for the file binscatter-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: binscatter-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 24.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for binscatter-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4dfa72f557182568fe1e6960df81fe1a062e779a41072244c11f6c6b261448be
MD5 6527b757920c6cc6744deda81fe70a77
BLAKE2b-256 bdb664334f92df8ef0a7cd58c16751d26495c8c8aab2f30a69f98fbbec474098

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page