Friday, May 17, 2019

Published 10:23 PM by with 0 comment

Plotly Hover Works but the Point Is Not Rendered

Sometimes when using plotly, you'll plot something, it won't show up, and hovering over the point that didn't show up will work. What's going on?

Situation 1

You've hit a bug. There are many that can cause this, particularly with 'scattergl'. Examples are here and here.


There is a non-buggy way to have this happen. If you are in 'lines' mode and you plot a point that connects to no other points, you will get this behavior. A simple example is a plot of a single point. A less trivial example is something like the following:
  • x: [1, NaN, 2, NaN, 3]
  • y: [1, NaN, 2, NaN, 3]
As I've covered before, NaN's are not interpolated to in lines mode. The points above will not be rendered. Hover will work however. There is a workaround if you can stand the performance drop though. Simply use 'lines+markers'. The performance impact will vary based on your data set, but I've seen it generally be about 50% slower.

I have embedded a simple example below and the code is here. These two plots are identical except that one uses 'lines' and one uses 'lines+markers'. You can easily see the 'hidden points with working hover' behavior if you hover over (1,1) or (2,2) in the 'lines' plot:



Post a Comment