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; when you want more bins, override via num_bins.

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

This package implements binscatter plots following:

  • Cattaneo, Matias D.; Crump, Richard K.; Farrell, Max H.; Feng, Yingjie (2024), “On Binscatter,” American Economic Review, 114(5), 1488–1514. DOI: 10.1257/aer.20221576

Tests

  • Run the full backend matrix, including PySpark: just test
  • Use the faster run without PySpark: just 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.0.tar.gz (21.8 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.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for binscatter-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8d0152f6090a9d16d083063b17662ab538fa4965fa883e63b4a2f10bca9b8010
MD5 41222f9e9285c2d868d10cc33c4f84b4
BLAKE2b-256 919d0bac4951a72e1e3916f37be372a819ec025e9e28dc66dd2c660bed01dde9

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for binscatter-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbe3a0916499b2fdfd952abd369a53df765748e06c4fce82943d6e0aeafa91a5
MD5 96c3082fff8567b71a36131dc39c9047
BLAKE2b-256 675f89962f315103eb4f05402b87af017d9b65b4d84f52ff96c6c81117c99f99

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