---
url: /link-multiple-plots.md
description: How to link and synchronize multiple Jupyter Scatter instances.
---

# Link Multiple Scatter Plots

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.

## Simplest Example

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()`](./api#compose).

```py{7}
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.

```py
jscatter.compose([a, b], rows=2)
```

We can also change the row height as follows to shrink or grow the plots.

```py
jscatter.compose([a, b], rows=2, row_height=240)
```

## Synchronize View, Selection, & Hover

So good so far but the fun part starts when we link/synchronize the scatter
plots' views and selections.

```py{3-5}
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()`](./api#link):

```py
jscatter.link([a, b])
```

The result is the same as the previous [`compose()`](./api#compose) call.
