如何在 Python 3 中将数据点悬停在 Plotly 的折线图中时一次显示数据点及其标签?
How to show data points and it's labels at a time while hovering it in line graph in Plotly in Python 3?
我想在 PLOTLY 的折线图中添加数据点及其各自的标签,将其悬停时可见。
import plotly.plotly as py
import plotly.graph_objs as go
data = [
go.Scatter(
x = [1,2,3,4,5],
y = [2,1,6,4,4],
text = ["Text A", "Text B", "Text C", "Text D", "Text E"],
hoverinfo = 'text',
marker = dict(
color = 'green'
),
showlegend = True,textposition='top center'
)
]
py.iplot(data, filename = "add-hover-text")
然后我做了 hoverinfo = 'y'
,显示像,
我已经编写了代码,但它显示的不是数据点就是文本中定义的标签。我想同时展示两者。你能帮我一次显示数据点和它的标签吗?
只需将您的 hoverinfo = 'text',
更改为 hoverinfo = 'text+y',
hoverinfo
帮助指出:
The 'hoverinfo' property is a flaglist and may be specified
as a string containing:
- Any combination of ['x', 'y', 'z', 'text', 'name'] joined with '+' characters
(e.g. 'x+y')
OR exactly one of ['all', 'none', 'skip'] (e.g. 'skip')
- A list or array of the above
我想在 PLOTLY 的折线图中添加数据点及其各自的标签,将其悬停时可见。
import plotly.plotly as py
import plotly.graph_objs as go
data = [
go.Scatter(
x = [1,2,3,4,5],
y = [2,1,6,4,4],
text = ["Text A", "Text B", "Text C", "Text D", "Text E"],
hoverinfo = 'text',
marker = dict(
color = 'green'
),
showlegend = True,textposition='top center'
)
]
py.iplot(data, filename = "add-hover-text")
然后我做了 hoverinfo = 'y'
,显示像,
我已经编写了代码,但它显示的不是数据点就是文本中定义的标签。我想同时展示两者。你能帮我一次显示数据点和它的标签吗?
只需将您的 hoverinfo = 'text',
更改为 hoverinfo = 'text+y',
hoverinfo
帮助指出:
The 'hoverinfo' property is a flaglist and may be specified
as a string containing:
- Any combination of ['x', 'y', 'z', 'text', 'name'] joined with '+' characters
(e.g. 'x+y')
OR exactly one of ['all', 'none', 'skip'] (e.g. 'skip')
- A list or array of the above