Python Plotly Scatterpolar悬停模式显示多个数据点

2024-09-26 18:07:25 发布

您现在位置:Python中文网/ 问答频道 /正文

使用Jupyter笔记本,我使用以下代码绘制了一个带有两条轨迹的散极图:

import numpy as np
import plotly.graph_objs as go

th = np.arange(0, 361, 1)
r1 = np.random.randn(360)
r2 = np.random.randn(360)

fig = go.Figure()
fig.add_trace(go.Scatterpolar(r=r1, theta=th, mode='lines'))
fig.add_trace(go.Scatterpolar(r=r2, theta=th, mode='lines'))
fig.update_layout(hovermode='x')

结果是这个图,当我将鼠标悬停在绘图上时,它不会同时显示两个数据点。我希望它显示两个数据点

enter image description here

例如,当你有一个直线图,这是很容易做到的。您只需更改hovermode='x',就会得到如hovermode text and formatting documentation所示的结果

enter image description here

当我将鼠标悬停在散极图上时,如何使散极图显示两个数据点?任何帮助都将不胜感激


Tags: 数据importaddgoasnpfigtrace
1条回答
网友
1楼 · 发布于 2024-09-26 18:07:25

我不知道我是否完全理解了你的最终目标,但你能做的第一件事是让散点图不那么混乱,那就是做出改变。默认情况下,光标下方的点将显示一个单独的悬停标签,因此,如果将光标悬停在具有(r1,th)坐标的点上,这些坐标将显示在标签中,具有(r2,th)坐标的点也会出现同样的情况。现在对于您介绍的案例,行fig.update_layout(hovermode='x unified')对结果没有任何影响

相关问题 更多 >

    热门问题