Black Lives Matter. Please consider donating to Black Girls Code today.

Is it possible to link selections across Plotly plots?

I’m making multiple scatter plots based on the same data source - i.e. the markers on each plot represent the same set of samples. To put it another way, if my data is in a table or dataframe, my different plots may have different axes and may use different columns of the dataframe, but each plot will contain one marker per row of the dataframe.

I’m wondering if it’s possible to do what bokeh calls “linked selections”. That is, if I make two plots - I assume these would need to be subplots - can I set them up such that selecting a set of markers on one plot will also select and highlight the corresponding set of markers on the other plot?

I’m specifically using the Python API but really my question is more generally whether the feature exists in Plotly.

Thanks for any help!

I’ve looked through the documentation and forums, apologies if I have missed an obvious answer to this.

1 Like

Hi @clare - We use this library internally to make linked views between plots in dashboards:

You can see some example code in this Codepen and the examples folder in the link above:

A growing list of Plotly dashboards that use crossfilter is compiled here:

And 2 other examples:

You mentioned Bokeh but your question is tagged “plotly.js”, so I assumed you’re looking for a JavaScript solution. If you’re looking for a Python solution, you can use Dash with Plotly to achieve linked views. See the Graph Crossfilter section here on how to do this:

Hope this helps!

Hi @jack - I just noticed that although I saw it at the time, I failed to reply to your reply. Belated thanks!

I was mostly after a Python solution, sorry for the misleading tag. And I have since tried Dash. I like Dash but would be interested to know if linked selections ever get explicitly added to the Plotly Python API (in the way that linked axes already are). Cheers!

1 Like

Awesome, thanks! It really is cool. Can we do the same but for hovering rather than selection?

I.e. hovering mouse over a value in one subplot would simultaneously show up hover label for the corresponding row in all other subplots

Thanks for your time in advance

I didn’t see an answer when I looked for this but it is pretty easy to do. Here is an example:

The first bit covers linking hovers, and the second bit covers linking zoom/pan behavior.