简体   繁体   English

Python Plotly - 如何更改光标和信息(注释)框之间的距离?

[英]Python Plotly - How to change the distance between the cursor and the information (annotation) box?

I am using Plotly to chart a Sine wave (see code below).我正在使用 Plotly 绘制正弦波图(请参见下面的代码)。 I would like to increase the distance between the cursor and its information box.我想增加光标与其信息框之间的距离。 Any help regarding how to change the distance is appreciated.感谢您提供有关如何更改距离的任何帮助。

import plotly.graph_objs as go 
import numpy as np
# Generate data for sine wave
x = np.linspace(0, 2*np.pi, 100) 
y = np.sin(x)
# Create figure
fig = go.Figure(data=[go.Scatter(x=x, y=y)])
# Display the x and y values when moving the cursor.
fig.update_layout(hovermode = 'x unified')
#Show figure
fig.show()

hoverdistance sets the distance to look for data to use for the hover label, rather than the distance of the hover label from the datapoint. hoverdistance 设置查找数据以用于悬停标签的距离,而不是悬停标签与数据点的距离。 So, you could remove that line as I don't think that's what you're trying to do.因此,您可以删除该行,因为我认为这不是您想要做的。

There's no option to set the distance between the point and the hoverlabel as far as I'm aware, this is a reported issue here: Reported issue据我所知,没有选项可以设置点和悬停标签之间的距离,这是一个报告的问题: Reported issue

One option may be to set the bgcolor to something that's transparent:一种选择可能是将 bgcolor 设置为透明的颜色:

`fig.update_layout(hovermode = 'x unified', hoverlabel=dict(bgcolor='rgba(255,255,255,0.1)'))`

At least that way you can still see the plot behind, if that's what your concern is about.至少这样你仍然可以看到背后的阴谋,如果那是你所关心的。

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

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