Просто включите '%{text}'
в hovertemplate
и назначьте ['z {}'.format(i) for i in data['z']]
на text
в go.Scatter()
, чтобы получить:
Полный код:
import pandas as pd
data= pd.DataFrame({'x': {0: 52.8, 1: 48.4, 2: 44.0, 3: 39.6, 4: 35.2},
'y': {0: 34.2, 1: 34.2, 2: 34.2, 3: 34.2, 4: 34.2},
'z': {0: 94.232224, 1: 95.520638, 2: 95.688486, 3: 93.810213, 4: 95.1804},
'M': {0: 1.347599,
1: 1.4104379999999999,
2: 1.3535409999999999,
3: 1.478019,
4: 1.163945}})
fig = go.Figure(go.Scatter(mode="markers", x=data['x'], y=data['y'], marker_symbol="square",
hovertemplate = 'y: %{y}'+'<br>x: %{x}<br>'+'%{text}',
text = ['z {}'.format(i) for i in data['z']],
marker_line_color="midnightblue",
marker_color="lightskyblue",
marker_line_width=1, marker_size=5))
fig.show()