Showing index and coordinates on tooltip

Hello guys, I have a scatterplot here but I would love to actually show the index of the marker and the coordinates at the same time… how do I do this?

I have seen that you might be able to do that with hoverinfo and text, but I tried that and had no luck.

I mean showing it like this:

Index: index \n
(x, y)

text = 'Index: {}'.format(index) 

this should do it (added to the trace). the coordinates will show first though, then the text you added.

Thanks for your answer

My issue however is with the value of the index variable that you put there. How am I to get the value of the index of the corresponding coordinates?

If I simply do:

'text': 'Index: {}'.format(df.index)

Then it will obviously just print the whole list of indexes.

05

maybe you could try 'text':'Index'+[df.index]?

Your text variable needs to be a list (or pandas Series?) with the same length as the data. Your try above will result in a single value (something like "Index: RangeIndex(1, 20)"), while Ola’s suggestion will likely result in an error.

I think that 'text': ('Index: ' + df.index).tolist() should work. The .tolist() may be unnecessary.

So looking back at your original post, it looks like you’re not going to get what you want, which is the actual value being shown. I think that 'text': df.index.to_series() + '\n( ' + df['COORDENADA_X_PT'] + ', ' + df['COORDENADA_Y_PT'] + ')' should do what you actually want.

PS. The .tolist() above should be unnecessary.