Elena Greg
Elena Greg

Reputation: 1165

How to add information to interactive label in plotly?

I have the following code and I would like to add information about each point from columns C, D, F to an interactive label (a label that appears after pointing the mouse on a point).

import plotly.express as px
import numpy as np
import pandas as pd
from plotly.graph_objs import *
import plotly.graph_objects as go

popisky = np.loadtxt('f.dat', unpack=True, dtype='str', usecols=[6])

data_n = np.loadtxt('f.dat', unpack=True, usecols=[0, 2, 5, 7])

data = data_n.tolist()
d = {'A': data[0], 'B': data[1], 'C': data[2], 'D': popisky, 'F': data[3]}

fig = px.scatter(df, x='A', y='B')


fig.show()

Upvotes: 0

Views: 556

Answers (1)

mad
mad

Reputation: 400

Just use hover_data:

fig = px.scatter(df, x='A', y='B', hover_data=["C", "D", "F"])

It is documented here: https://plotly.com/python/hover-text-and-formatting/#customizing-hover-text-with-plotly-express

Upvotes: 1

Related Questions