简体   繁体   English

Python Plotly 散极悬停模式

[英]Python Plotly Scatterpolar hovermode

I'm new to Python and programming in general.我是 Python 和一般编程的新手。 Using Jupyter Notebooks, I made a Scatterpolar plot with two traces on it.使用 Jupyter Notebooks,我制作了一个带有两条迹线的 Scatterpolar plot。 When I hover my mouse over the plot, it shows me the data for one of the traces (the one that my mouse is closest to).当我将鼠标 hover 放在 plot 上时,它向我显示了其中一条轨迹的数据(我的鼠标最接近的轨迹)。 But I want to see the data for both traces.但我想查看两条迹线的数据。 How do I do that?我怎么做? I can do it with a regular Scatter plot by changing the "hovermode" to "x."我可以通过将“悬停模式”更改为“x”来使用常规的 Scatter plot 来做到这一点。 But it doesn't work with Scatterpolar plots.但它不适用于 Scatterpolar 图。 The other options for hovermode didn't work for me either.悬停模式的其他选项对我也不起作用。

As an example, I put some simpler code here to illustrate the issue:作为一个例子,我在这里放了一些更简单的代码来说明这个问题:

import numpy as np
from plotly.offline import iplot
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 unified')

Using the above code in a Jupyter Notebook, I get two messy traces on a polar plot, and when I hover my mouse over it I only see data for one of the traces.在 Jupyter Notebook 中使用上述代码,我在极坐标 plot 上得到两条凌乱的轨迹,当我将鼠标悬停在 hover 上时,我只看到其中一条轨迹的数据。 I want to see the data for both traces.我想查看两条迹线的数据。 Any help would be greatly appreciated.任何帮助将不胜感激。 Thanks so much!非常感谢!

I don't know if I fully comprehended your final objective, but the first thing you can do to make the scatter plots less messy, is to make the change mode='markers' .我不知道我是否完全理解了你的最终目标,但你可以做的第一件事是让散点图不那么混乱,就是让 change mode='markers' By default, a single hover label will appear for the point underneath the cursor, so if you hover over a point with (r1, th) coordinates these will show in the label, with the same happening for points with (r2, th). By default, a single hover label will appear for the point underneath the cursor, so if you hover over a point with (r1, th) coordinates these will show in the label, with the same happening for points with (r2, th). Now for the case you presented, the line fig.update_layout(hovermode='x unified') doesn't make any difference to the result.现在对于您提出的情况, fig.update_layout(hovermode='x unified')行对结果没有任何影响。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM