Display (a different) value under scatter point


#1

Plotlyjs is giving me a plot that doesn’t seem to be finding the closest scatter point to my cursor (indicated by black arrow):

using Plots
plotlyjs()
scatter(x1, x2)

My question is:

  1. How can I display the name of each point based on x- and y- coordinate of my cursor?
  2. If I actually want the displayed value to be different, how can I change that? For instance, I am plotting the 5th and 6th column of a dataframe (see image below), but when I hover over the points, I want to display the corresponding values in the 3rd and 4th column:


#2

try the hover attribute


#3

Thank you, I was able to add the name to the points. However the plots are still not displaying the node that is closest to my cursor. Do you know how to fix this?

For future reference, this is how I did it:

#construct the name array
name = Array{String}(size(x, 1))
for i in 1:length(name)
name[i] = x[i, 3] * " & " * x[i, 4]
end

scatter(x[:empiric_kinship], x[:theoretical_kinship],
xlabel = “empiric kinship”, ylabel = “theoretical kinship (θ)”,
hover = name)


#4

Yes there’s something fishy going on with the plotly hovers and the mouse position, always have been. Not even sure this is Plots creating trouble or happens in plotly itself.
It’s actually really annoying, but not sure how to fix.


#5

There’s a button in the top right corner of the plot that switches between “show all points” and “show closest point”. Have you tried that?


#6

Ahhhhhhhhhhh I feel stupid. Thank you so much. It works!


#7

If you want to change the behavior programatically, you can do

p=plot(); PlotlyJS.relayout!(p.o,hovermode="closest")

Alternative values are "x" (the default) and "y" (which doesn’t seem to be accessible from the GUI).


#8

What! I feel even more stupid :open_mouth:
:heart: