jupyter-scatter
jupyter-scatter (the jscatter package) is a GPU-accelerated scatter plot: every point renders on the GPU instead of the DOM, so it stays interactive into the millions of points, with lasso selection, hover tooltips, and animated transitions built in.

3,000 cars, colored by origin, after lassoing most of the plot. Try the app.
Installation
pip install 'shinywidgets[jscatter]'This installs jupyter-scatter itself. jupyter-scatter is built on anywidget, so there are no extra JavaScript assets to configure – its bundle ships inside the Python package.
Quick start
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import render, ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(1)
n = 3000
origin = pd.Series(rng.choice(["USA", "Europe", "Japan"], n, p=[0.5, 0.25, 0.25]))
weight = origin.map({"USA": 3.4, "Europe": 2.6, "Japan": 2.4}) + rng.normal(0, 0.5, n)
cars = pd.DataFrame(
{
"origin": origin.astype("category"),
"weight": weight.round(2),
"mpg": (45 - 6 * weight + rng.normal(0, 2.5, n)).round(1),
}
)
ui.page_opts(title="jupyter-scatter quick start", fillable=True)
with ui.card(full_screen=True):
ui.card_header("Weight vs. MPG, colored by origin")
@render_jscatter
def plot():
return (
Scatter(data=cars, x="weight", y="mpg", color_by="origin")
.axes(labels=["Weight (1000 lbs)", "MPG"])
.lasso(initiator=True)
)
@render.text
def n_selected():
return f"{len(plot.selected())} of {len(cars)} selected"@render_jscatter takes a jscatter.Scatter builder (or its underlying JupyterScatter widget) and turns its lasso/click selection into the reactive values plot.selected() and plot.selected_rows(). .lasso(initiator=True) lets a user start a lasso with a click-and-drag from anywhere, in addition to the default long-press gesture; both reach plot.selected() the same way.
Overview
A look at what you can build. Click any of them to open the app, with its code, in Shinylive.
A 300,000-cell atlas explorer
Two million points, interactively
Linked brushing between two plots
Lasso selection drives a table
A table selection highlights the plot
Recolor without losing the view
Select and filter from Python
Animated transition between embeddings
The lasso selection as a reactive value
Read hover, zoom, and lasso shape
Tooltips with built-in histograms
Color, size, and opacity encodings
Download the selection on demand
Fill vs. fixed height
A linked-scatter starting template
Styling and encodings
Each of the following is a plain jupyter-scatter option – nothing Shiny-specific yet.
Color, size, and opacity encodings
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(3)
n = 4000
origin = pd.Series(rng.choice(["USA", "Europe", "Japan"], n, p=[0.5, 0.25, 0.25]))
weight = origin.map({"USA": 3.4, "Europe": 2.6, "Japan": 2.4}) + rng.normal(0, 0.5, n)
cars = pd.DataFrame(
{
"origin": origin.astype("category"),
"weight": weight.round(2),
"mpg": (45 - 6 * weight + rng.normal(0, 2.5, n)).round(1),
"hp": (45 * weight + rng.normal(0, 25, n)).round(),
}
)
ui.page_opts(title="Color, size, and opacity encodings", fillable=True)
with ui.card(full_screen=True):
ui.card_header("Color = origin, size and opacity = horsepower")
@render_jscatter
def plot():
# jscatter allows at most 2 distinct *data dimensions* driving
# color/size/opacity at once; reuse one dimension (here "hp") across
# more than one channel to combine three encodings anyway.
return (
Scatter(data=cars, x="weight", y="mpg")
.color(by="origin")
.size(by="hp", map=[2, 4, 6, 8, 10])
.opacity(by="hp")
.legend(True)
)
.color(), .size(), and .opacity() all take by= (a column name or array) plus map= for the color/size scale. The legend (.legend(True)) reflects whatever is encoded. At most 2 distinct data columns can drive color/size/opacity combined – a third distinct column raises AssertionError: Only 2 data encodings are supported. Reusing one column across two channels (as above, hp for both size and opacity) doesn’t count twice.
Tooltips with built-in histograms
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(4)
n = 500
origin = pd.Series(rng.choice(["USA", "Europe", "Japan"], n, p=[0.5, 0.25, 0.25]))
weight = origin.map({"USA": 3.4, "Europe": 2.6, "Japan": 2.4}) + rng.normal(0, 0.5, n)
cars = pd.DataFrame(
{
"model": [f"Car {i}" for i in range(n)],
"origin": origin.astype("category"),
"weight": weight.round(2),
"mpg": (45 - 6 * weight + rng.normal(0, 2.5, n)).round(1),
}
)
ui.page_opts(title="Tooltips", fillable=True)
ui.p("Hover a point to see its data, right in the plot.")
with ui.card(full_screen=True):
@render_jscatter
def plot():
return (
Scatter(data=cars, x="weight", y="mpg", color_by="origin")
.tooltip(True, properties=["x", "y", "color", "model"])
)
properties names the visual channels ("x", "y", "color", "opacity", "size") that are already encoded, plus any other data column by name ("model" here) – it draws a mini histogram next to each numeric property for free. This is entirely client-side: hovering doesn’t round-trip to Python (see .read() if you need the hovered point in Python too).
Reacting to interaction
Every @render_jscatter output has accessors that report what the user did: plot.selected() and plot.selected_rows(), and more. Call one from any reactive context, the same way you’d call input.my_slider(), and that context re-runs whenever the selection changes.
Selecting points with the lasso
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import render, ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(1)
n = 3000
origin = pd.Series(rng.choice(["USA", "Europe", "Japan"], n, p=[0.5, 0.25, 0.25]))
weight = origin.map({"USA": 3.4, "Europe": 2.6, "Japan": 2.4}) + rng.normal(0, 0.5, n)
cars = pd.DataFrame(
{
"origin": origin.astype("category"),
"weight": weight.round(2),
"mpg": (45 - 6 * weight + rng.normal(0, 2.5, n)).round(1),
}
)
ui.page_opts(title="plot.selected()", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
@render_jscatter
def plot():
return Scatter(data=cars, x="weight", y="mpg", color_by="origin").lasso(
initiator=True
)
with ui.card(full_screen=True):
@render.text
def n_selected():
return f"{len(plot.selected())} of {len(cars)} cars selected"
@render.data_frame
def selected_cars():
return plot.selected_rows()

selected() holds row positions into whatever data frame built the plot, not index labels – the right shape for programmatic selection and filtering (see Updating in place), where the setters also take positions. If you build the plot with Scatter(..., data_use_index=True) and want index labels instead, read plot.value.selection() (the builder’s own method) rather than the accessor. A re-render (e.g., the render function reading an input) gives the user a brand new plot whose selection starts empty; selected() can’t be read inside plot’s own render function for the same reason .widget can’t – read it from another output or a @reactive.effect.
Updating in place
Two ways to change an already-rendered plot, and when each is right:
- Re-render (have the render function return a new
Scatter): simplest, but jupyter-scatter re-sends the full point data and the view resets – camera, zoom, and selection are all lost. Fine for small data or when the whole plot is genuinely changing (e.g., a different data frame entirely). - Update in place, from a
@reactive.effect, reading the input that should drive the change and calling a method onplot.value(theScatterbuilder) or setting a trait directly onplot.widget, both wrapped inreactive.isolate()so reading the current state of the plot doesn’t create a reactive dependency that would re-run the effect in a loop. This is almost always what you want for anything short of swapping the dataset: the camera, zoom, and selection are preserved, and neither the point data nor jupyter-scatter’s own JS bundle is re-sent.
The example below shows the .value form, recoloring a plot from categorical to continuous on a button click without re-rendering or losing the current view:
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny import reactive
from shiny.express import input, render, ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(1)
n = 3000
origin = pd.Series(rng.choice(["USA", "Europe", "Japan"], n, p=[0.5, 0.25, 0.25]))
weight = origin.map({"USA": 3.4, "Europe": 2.6, "Japan": 2.4}) + rng.normal(0, 0.5, n)
cars = pd.DataFrame({"origin": origin.astype("category"), "weight": weight.round(2)})
cars["mpg"] = (45 - 6 * cars["weight"] + rng.normal(0, 2.5, n)).round(1)
ui.page_opts(title="Restyle in place, without re-sending data", fillable=True)
ui.input_action_button("toggle", "Color by weight instead", class_="mb-2")
with ui.card(full_screen=True):
@render_jscatter
def plot():
return Scatter(data=cars, x="weight", y="mpg", color_by="origin")
@reactive.effect
@reactive.event(input.toggle)
def _recolor():
by_weight = input.toggle() % 2 == 1
with reactive.isolate():
if by_weight:
plot.value.color(by="weight", map="viridis")
else:
plot.value.color(by="origin")

Animated transitions between embeddings
.xy(x=, y=, animate=True) is the one call that moves both coordinates at once and tweens between them – exactly the pattern for comparing two embeddings of the same points (PCA vs. UMAP, before vs. after a model update, raw vs. batch-corrected). Call it on plot.value (the Scatter builder) inside reactive.isolate(), the same as any other in-place update:
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny import reactive
from shiny.express import input, render, ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(2)
n = 600
label = rng.integers(0, 5, n)
grid_x, grid_y = (np.arange(n) % 30).astype(float), (np.arange(n) // 30).astype(float)
angle = rng.uniform(0, 2 * np.pi, n)
radius = label + rng.normal(0, 0.15, n)
points = pd.DataFrame(
{
"grid_x": grid_x,
"grid_y": grid_y,
"circle_x": radius * np.cos(angle),
"circle_y": radius * np.sin(angle),
"label": label.astype(str),
}
)
ui.page_opts(title="Animated transition between embeddings", fillable=True)
ui.input_action_button("toggle", "Switch embedding", class_="mb-2")
with ui.card(full_screen=True):
@render_jscatter
def plot():
return Scatter(data=points, x="grid_x", y="grid_y", color_by="label")
@reactive.effect
@reactive.event(input.toggle)
def _switch():
to_circle = input.toggle() % 2 == 1
x, y = ("circle_x", "circle_y") if to_circle else ("grid_x", "grid_y")
with reactive.isolate():
plot.value.xy(x=x, y=y, animate=True)Clicking “Switch embedding” re-lays the same points out on a circle, animated, with each point keeping its color:


Selecting and filtering from Python
The example below drives both selection and filter straight from Python, by assigning the widget’s traits directly (the form the class docstring recommends) rather than chaining Scatter methods:
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny import reactive
from shiny.express import input, render, ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(1)
n = 3000
origin = pd.Series(rng.choice(["USA", "Europe", "Japan"], n, p=[0.5, 0.25, 0.25]))
weight = origin.map({"USA": 3.4, "Europe": 2.6, "Japan": 2.4}) + rng.normal(0, 0.5, n)
cars = pd.DataFrame({"origin": origin.astype("category"), "weight": weight.round(2)})
cars["mpg"] = (45 - 6 * cars["weight"] + rng.normal(0, 2.5, n)).round(1)
ui.page_opts(title="Drive selection and filter from Python", fillable=True)
with ui.layout_columns(col_widths=[4, 4, 4]):
ui.input_action_button("select_heavy", "Select heaviest 10%")
ui.input_action_button("filter_usa", "Filter to USA only")
ui.input_action_button("reset", "Reset")
with ui.card(full_screen=True):
@render_jscatter
def plot():
return Scatter(data=cars, x="weight", y="mpg", color_by="origin")
@reactive.effect
@reactive.event(input.select_heavy)
def _select():
cutoff = cars["weight"].quantile(0.9)
ids = np.flatnonzero(cars["weight"] >= cutoff).astype("uint32")
with reactive.isolate():
plot.widget.selection = ids
@reactive.effect
@reactive.event(input.filter_usa)
def _filter():
ids = np.flatnonzero(cars["origin"] == "USA").astype("uint32")
with reactive.isolate():
plot.widget.filter = ids
@reactive.effect
@reactive.event(input.reset)
def _reset():
with reactive.isolate():
plot.widget.selection = np.array([], dtype="uint32")
plot.widget.filter = None
@render.text
def n_selected():
return f"{len(plot.selected()):,} selected"Clicking “Select heaviest 10%” rings the selected points without hiding the rest; “Filter to USA only” hides the other points entirely instead of just marking them:


selection highlights points without hiding anything else; filter hides everything not in the given set of positions. Both take uint32 arrays of row positions (or index labels if the Scatter was built with data_use_index=True); set either to None (filter) or an empty array (selection) to clear it. Both also have chainable equivalents on the Scatter builder (plot.value.selection(ids), plot.value.filter(ids)) if you’re already calling other builder methods in the same effect.
Linking widgets
Linked brushing between plots
The example below mirrors each plot’s lasso selection onto the other, so selecting the same underlying rows highlights consistently regardless of which plot the user dragged on:
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny import reactive
from shiny.express import ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(1)
n = 3000
origin = pd.Series(rng.choice(["USA", "Europe", "Japan"], n, p=[0.5, 0.25, 0.25]))
weight = origin.map({"USA": 3.4, "Europe": 2.6, "Japan": 2.4}) + rng.normal(0, 0.5, n)
cars = pd.DataFrame({"origin": origin.astype("category"), "weight": weight.round(2)})
cars["mpg"] = (45 - 6 * cars["weight"] + rng.normal(0, 2.5, n)).round(1)
cars["hp"] = (45 * cars["weight"] + rng.normal(0, 25, n)).round()
ui.page_opts(title="Linked brushing between two jscatter plots", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
ui.card_header("Weight vs. MPG")
@render_jscatter
def weight_mpg():
return Scatter(data=cars, x="weight", y="mpg", color_by="origin").lasso(
initiator=True
)
with ui.card(full_screen=True):
ui.card_header("Horsepower vs. MPG")
@render_jscatter
def hp_mpg():
return Scatter(data=cars, x="hp", y="mpg", color_by="origin").lasso(
initiator=True
)
def link(source, target):
@reactive.effect
def _():
selection = source.selected()
with reactive.isolate():
if not np.array_equal(selection, target.widget.selection):
target.widget.selection = selection
link(weight_mpg, hp_mpg)
link(hp_mpg, weight_mpg)Lassoing the lighter half of the weight/MPG plot lights up the same cars in the horsepower plot, which has its own, uncorrelated noise:


The np.array_equal guard is load-bearing: without it, each plot setting the other’s selection would trigger the other effect right back, which (even though it converges) does unnecessary work on every gesture.
Lasso selection drives a table
The example below feeds selected_rows() into an itables table, re-rendered to show only the lassoed rows – a different widget library entirely, linked with one line of Python:
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import ui
from shinywidgets import render_itables, render_jscatter
rng = np.random.default_rng(1)
n = 1500
origin = pd.Series(rng.choice(["USA", "Europe", "Japan"], n, p=[0.5, 0.25, 0.25]))
weight = origin.map({"USA": 3.4, "Europe": 2.6, "Japan": 2.4}) + rng.normal(0, 0.5, n)
cars = pd.DataFrame({"origin": origin.astype("category"), "weight": weight.round(2)})
cars["mpg"] = (45 - 6 * cars["weight"] + rng.normal(0, 2.5, n)).round(1)
ui.page_opts(title="Lasso selection drives an itables table", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
@render_jscatter
def plot():
return Scatter(data=cars, x="weight", y="mpg", color_by="origin").lasso(
initiator=True
)
with ui.card(full_screen=True):
ui.card_header("Rows inside the lasso")
@render_itables
def table():
return plot.selected_rows()

This re-renders the table on every selection change rather than updating it in place – simple, and cheap enough for tables up to a few tens of thousands of rows. For a table that’s expensive to rebuild, read plot.selected_rows() in an effect and call .widget.update(...) (see the itables guide) instead.
Table selection highlights the plot
The same link, run the other way: the example below uses Shiny’s own @render.data_frame row selection to highlight matching points in a jscatter plot.
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny import reactive, req
from shiny.express import render, ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(6)
cars = pd.DataFrame(
{
"model": [f"Car {i}" for i in range(60)],
"weight": rng.uniform(1.8, 4.5, 60).round(2),
"mpg": rng.uniform(14, 44, 60).round(1),
}
)
ui.page_opts(title="Table row selection highlights the plot", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
@render.data_frame
def table():
return render.DataGrid(cars, selection_mode="rows")
with ui.card(full_screen=True):
@render_jscatter
def plot():
return Scatter(data=cars, x="weight", y="mpg")
@reactive.effect
def _highlight():
rows = table.cell_selection()["rows"]
w = plot.widget
req(w)
ids = np.array(rows, dtype="uint32")
with reactive.isolate():
w.selection = ids

table.cell_selection()["rows"] gives row positions in the table’s own display order; since this example builds both the table and the plot from the identical, unsorted cars frame, those positions line up directly with plot.widget.selection’s row positions. If your table can be sorted or filtered, map through the visible-row positions first (see the ipydatagrid or itables guides).
Accessor reference
| Accessor | Returns | Before any interaction | Across a re-render | Default rate policy |
|---|---|---|---|---|
selected() |
numpy.ndarray (uint32) of row positions |
seeded: empty array (every normal Scatter(...)-returning render); cancels instead, for a bare JupyterScatter built without going through Scatter, until the browser reports once |
re-seeded: a new plot’s selection starts empty | none (reports once per gesture, not during the drag) |
selected_rows(df=None) |
the selected rows of df (default: the frame the Scatter was built with), in df’s own type (pandas, polars, …) |
empty frame (cancels when selected() does) |
derived from selected() |
none (follows selected()) |
selected() cancels the same way reading .widget does before first render – and, only for a bare JupyterScatter constructed without going through Scatter, continues to cancel until the browser reports once. Every normal Scatter(...)-returning render function starts selected() at an empty array immediately instead, since Scatter itself seeds the widget’s selection trait.
selected_rows()
Pass a frame explicitly – plot.selected_rows(df) – when the render function returns a bare JupyterScatter (which retains no frame), or when the plot’s rows aren’t your frame’s rows in order. Any frame type works: pandas in, pandas out; polars in, polars out. The match is positional, like df.iloc[plot.selected()] – after a re-render or in-place data replacement with different rows, a retained position can point at a different row, so carry an ID column and look rows up by it when the data can change.
Tuning accessors
Reading on demand
selected_rows() is seeded empty the moment a Scatter(...)-built plot renders, so it’s safe to read from somewhere that only runs occasionally – a download handler, say – with no prior interaction needed first:
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import render, ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(1)
n = 2000
points = pd.DataFrame({"x": rng.uniform(0, 1, n), "y": rng.uniform(0, 1, n)})
ui.page_opts(title="Reading selected_rows() on demand", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
ui.card_header("Lasso some points, then download -- no need to click anything first")
@render_jscatter
def plot():
return Scatter(data=points, x="x", y="y").lasso(initiator=True)
with ui.card():
@render.download_button(
filename="selected.csv", label="Download selected points as CSV"
)
def download():
# selected_rows() is seeded empty the moment the plot renders, so
# this reads whatever's currently selected, even on first run.
yield plot.selected_rows().to_csv(index=False)

Rate limiting
jupyter-scatter reports selection once when a gesture ends, not continuously during the drag, so render_jscatter’s selected() has no default rate policy – there’s nothing streaming to coalesce. If you share one plot across many sessions (a process-global or shared_lifetime() widget) and several sessions react to the same selection with expensive work, pass rate_policy="debounce" and rate_delay= to @render_jscatter(...), the same two keyword arguments every renderer in this roster accepts. There’s no jscatter-specific tuning beyond deciding whether you need this at all.
.read()
hovering, zoom_level, and lasso_selection_polygon are synced traits of the plot’s own widget, with no dedicated accessor. Because they’re traits of the output’s own widget (not a nested object), plot.read(name) reaches them directly – no reactive_read(), and no req(plot.widget) guard to write yourself; .read() cancels on its own until the plot first renders, the same way the selected() accessor does.
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import render, ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(5)
n = 400
points = pd.DataFrame({"x": rng.uniform(0, 1, n), "y": rng.uniform(0, 1, n)})
ui.page_opts(title="Beyond the accessor: .read()", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
@render_jscatter
def plot():
return Scatter(data=points, x="x", y="y").lasso(initiator=True)
with ui.card():
ui.card_header("Traits plot.read() can reach")
@render.text
def hovering():
idx = plot.read("hovering")
return f"hovering: {'none' if idx is None else idx}"
@render.text
def zoom_level():
return f"zoom_level: {plot.read('zoom_level'):.2f}"
@render.text
def lasso_polygon():
poly = plot.read("lasso_selection_polygon")
return f"lasso_selection_polygon: {'none' if poly is None else f'{len(poly)} vertices'}"Hovering a point, scroll-zooming, and lassoing updates all three traits:


Three widget traits are worth reading this way beyond the selected() accessor:
hovering: the row position under the cursor, orNone. Updates on every mouse move over a point – don’t feed it straight into an expensive computation without debouncing.zoom_level: a read-only float that tracks the camera’s zoom factor, updated on every scroll/pan.lasso_selection_polygon: the lasso’s own vertices in data coordinates (an(n, 2)array),Noneuntil the first lasso. Useful if you want the shape of the selection rather than just which points it contains (e.g., to draw the same region on a second, differently-scaled plot).
filter is also a synced trait, but nothing in jupyter-scatter’s UI writes to it; it’s Python-to-browser only (see Selecting and filtering from Python), so there’s no browser gesture to read it for.
Large data
jupyter-scatter’s whole premise is scale: every point is drawn by the GPU (via regl-scatterplot) instead of the DOM, so there’s no separate “large data mode” to opt into:
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import render, ui
from shinywidgets import render_jscatter
N = 2_000_000
rng = np.random.default_rng(0)
centers = rng.uniform(-5, 5, size=(8, 2))
cluster = rng.integers(0, 8, N)
xy = centers[cluster] + rng.normal(scale=0.6, size=(N, 2))
points = pd.DataFrame({"x": xy[:, 0], "y": xy[:, 1], "cluster": cluster.astype(str)})
ui.page_opts(title="2,000,000 points", fillable=True)
ui.p(f"{N:,} points on the GPU. Drag to pan, scroll to zoom, or lasso a cluster.")
with ui.card(full_screen=True):
@render_jscatter
def plot():
return (
Scatter(data=points, x="x", y="y", color_by="cluster")
.size(default=2)
.lasso(initiator=True)
)
@render.text
def n_selected():
return f"{len(plot.selected()):,} selected"This renders and stays responsive to pan, zoom, and lasso with 2 million points. Zoomed out, dense clusters blend into soft density blobs; scroll in and you see the individual points:


The practical ceiling isn’t rendering, it’s getting a selection back to Python: a lasso over roughly 3 million points can exceed Shiny’s default 16 MiB websocket message limit. Since #481 such an oversized message is dropped client-side with a sticky error notification – the app keeps running, but that selection never reaches Python. Raise the limit with shiny run --ws-max-size <bytes> (and set SHINYWIDGETS_WS_MAX_SIZE to match) if you lasso at that scale. This is the “draw it with the GPU in the browser” approach from Large data & performance.
Layout and sizing
A plot fills its output (card or page) unless it has a height of its own:
import numpy as np
import pandas as pd
from jscatter import Scatter
from shiny.express import ui
from shinywidgets import render_jscatter
rng = np.random.default_rng(7)
points = pd.DataFrame({"x": rng.uniform(0, 1, 500), "y": rng.uniform(0, 1, 500)})
ui.page_opts(title="Fill vs. fixed height", fillable=True)
with ui.layout_columns():
with ui.card(full_screen=True):
ui.card_header("Fills the card")
@render_jscatter
def fills():
return Scatter(data=points, x="x", y="y")
with ui.card():
ui.card_header("Fixed height (300px)")
@render_jscatter
def fixed():
return Scatter(data=points, x="x", y="y", height=300)
One quirk worth knowing: jupyter-scatter’s own default, Scatter(..., height=240), is specifically treated as “no height” and still fills: a plot built with height=240 fills a 372px card, while height=241 is honored as a fixed 241px plot. If you want a genuinely fixed 240px plot, ask for 241 (or anything else) instead. Once a plot has filled its output, Python can no longer resize it by setting .widget.height – the browser’s fit wins; choose the height at construction if you need a specific, unchanging size.
Gotchas
- Passing index labels (instead of positions) into
.widget.selectionselects the wrong rows silently, with no error, and can make.zoom(to=...)raise an out-of-range error instead. Pass positions, or build theScatterwithdata_use_index=Trueif you need to work in labels. jscatter.compose()and.link()return a plainipywidgets.GridBox, not aJupyterScatter, so@render_jscattercan’t render their result. Use@render_widgetinstead forcompose()’s layout (no fill behavior orselected()accessor), or render the plots as separate@render_jscatteroutputs and link them in Python (see Linking widgets).
In the gallery
Complete apps in the gallery that use jupyter-scatter:
Learn more
- jupyter-scatter documentation – the full
ScatterAPI: connections, annotations, label placement. - regl-scatterplot – the WebGL renderer jupyter-scatter is built on.
- itables and ipydatagrid – the table side of the linked-view patterns above.
- plotly and altair – for moderate data sizes where you also want axes, facets, or non-scatter marks.
- embedding-atlas – for a SQL-backed cross-filtering explorer across many chart types.