There are many use cases where one wants to create two or more scatter plot and potentially link the view, selection, and hover state.
For instance, we might want to
- visualize different properties of a dataset
- compare different facets of a dataset
- compare different embedding methods of a dataset
- compare multiple datasets with shared labels
Jupyter Scatter can help with this by composing and linking multiple scatter instances.
We'll start out with a very simple example to get familiar with the API.
In the following, we'll compose two scatter plots next to each other using
compose()
.
import jscatter
import numpy as np
x, y = np.random.rand(500), np.random.rand(500)
a, b = jscatter.Scatter(x=x, y=y), jscatter.Scatter(x=x, y=y)
jscatter.compose([a, b])
By default, jscatter arranges scatter plots into a single row but we can customize this of course.
jscatter.compose([a, b], rows=2)
We can also change the row height as follows to shrink or grow the plots.
jscatter.compose([a, b], rows=2, row_height=240)
So good so far but the fun part starts when we link/synchronize the scatter plots' views and selections.
jscatter.compose(
[a, b],
sync_view=True,
sync_selection=True,
sync_hover=True,
)
Since a common use case is to synchronize everything, jscatter
offers the
shorthand method link()
:
jscatter.link([a, b])
The result is the same as the previous compose()
call.