Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

[Resolved] Valid modes for plotly_selected

After some experimentation with the select event plotly_selected, I’ve noticed that
x: x_values,
y: y_values,
type: ‘scatter’,
mode: ‘markers’

allows the user to select points on the plot. However,
x: x_values,
y: y_values,
type: ‘scatter’,
mode: ‘lines’

Does not return any values after the event. (If you remove mode: 'lines', it looks like type: 'scatter' defaults to mode: 'lines' and so removing it doesn’t solve the issue.)

For my plot, I need to allow the user to select the points drawn up (as lines). This seems to be an issue, so my questions:

  1. For which modes are plotly_selected currently supported
  2. If plotly_selected currently supports mode: 'lines', what can I do to get my code to work?

I apologize if this has already been asked somewhere. I’ve been unable to locate it if it has.

Thank you in advance

That’s correct. Selection aren’t supported on lines yet. See https://github.com/plotly/plotly.js/issues/170#issuecomment-317063282 for more info.

Thanks @etienne

Here’s a workaround for anybody else that encounters the same problem.

When defining your data, define mode: 'lines+markers' and set a marker size

For example,

{
   name: 1,
   x: x,
   y: x,
   type: 'scatter',
   mode: 'lines+markers',
   marker: {
      size: 0.01,
   }
}

Then the plotly_selected will work. It’ll pick up the markers, but with the marker size so low the user won’t see the markers. I’m sure this increases overhead, but it does work.

{
   name: 1,
   x: x,
   y: x,
   type: 'scatter',
   mode: 'lines+markers',
   marker: {
      opacity: 0
   }
}

should perform even better.

1 Like