xy (reflex.dev) for letsplot optimizationLets-Plot is a multiplatform plotting library built on the principles of the Grammar of Graphics, bringing the ggplot2 experience to Python. However, most charting libraries (including those using ggplot2 paradigms) stop being usable somewhere in the hundreds of thousands of points. Working at scale normally means downsampling your data first or using sampling.
The open-source library xy by Reflex.dev renders a scatter plot of 100 million points that you can pan and zoom through in real time — without any pre-downsampling. Performance metrics: 0.071s at 10k and 0.081s at 100M, flat across four orders of magnitude.
src/)base_dim², each higher level is a 4→1 exact sum (u64 accumulate, saturating to u32), so every level conserves total count bit-exactlyjs/src/)_map) — nothing below may regress this45_lod.ts): tier selection, drill enter/exit hysteresis, cross-tier fades, and retained tier caches| Tier | Name | Representation | Cost model |
|---|---|---|---|
| 0 | Direct | every visible mark, exact | O(visible) verts |
| 1 | Shape-preserving reduction | per-pixel-column aggregate (M4 for lines) | O(px) verts |
| 2 | Density / aggregate surface | mean-point-color texture composited at points' own alpha | O(screen) texels |
| 3 | Out-of-core tiles | Tier-2 pyramid where not all tiles are resident | O(visible tiles) |
python/xy/config.py)# Lines longer than this ship M4-decimated (Tier 1)
DECIMATION_THRESHOLD = 10_000
# Scatter above this many points switches to Tier-2 density aggregation
SCATTER_DENSITY_THRESHOLD = 200_000
# Absolute direct-draw ceiling; above this, density is forced even with per-point channels
DIRECT_SOFT_CEILING = 2_000_000
# Hysteresis on the drill boundary: once drilled to points, stay until count clearly exceeds budget again
DRILL_EXIT_FACTOR = 1.15
python/xy/lod.py)The render tier is a function of the visible point count, hysteresis-guarded:
def drill_decision(visible: int, budget: float, in_drill: bool) -> bool:
"""Once drilled down to real points, stay until the count clearly exceeds the budget again."""
return visible <= budget * (DRILL_EXIT_FACTOR if in_drill else 1.0)
1 − (1 − a_pt)^k for k points with per-point alpha a_pt.
(v - offset) * scale so large-magnitude domains keep the digits that matter.For a cell with k points, each with per-point alpha a_pt, the displayed alpha is the physical compositing:
display_alpha = 1 − (1 − a_pt)^k
This saturates after a few points exactly like real overplotted marks do. The color is the alpha-weighted mean of resolved colors in linear light (integer pipeline: checked-in sRGB⇄linear-u16 tables, u64 sums — bitwise deterministic).