繁体   English   中英

Plotly:烛台图的恒定尖峰线

[英]Plotly: Constant Spike lines for Candlestick Charts

我目前正在尝试在 Python 中的 Plotly 上的烛台图表中添加尖峰线。

无论我的 cursor 在图表上的哪个位置,我都希望尖峰线跟随光标/鼠标的 y 坐标。 但是现在,只有当我的 cursor 在蜡烛上时,我才能得到一条尖峰。

我有以下用于尖峰线的代码:

fig.update_yaxes(showspikes = True, spikecolor = '#FB75FF', spikedash = 'solid',
                     spikesnap = 'cursor', spikemode = 'across', spikethickness = 1)
    fig.update_layout(spikedistance = 1000, hoverdistance = 100)

如果我可以在图表的边缘显示 y 坐标也很好。

这可能吗?

谢谢你。

添加

fig.update_yaxes(showline=True)

fig.update_layout(hovermode='x', spikedistance=-1)

不需要悬停距离。

只需包括:

fig.update_layout(hoverdistance=0)

示例 plot:

在此处输入图像描述

完整代码:

import pandas as pd
import numpy as np
import plotly.graph_objs as go
from plotly.subplots import make_subplots

df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv').iloc[:60]
fig = make_subplots(rows=2, cols=1, row_heights=[0.8, 0.2], vertical_spacing=0)

fig.add_trace(go.Candlestick(open=df['AAPL.Open'], high=df['AAPL.High'], low=df['AAPL.Low'], close=df['AAPL.Close'],
                             increasing_line_color='#0384fc', decreasing_line_color='#e8482c', name='AAPL'), row=1, col=1)

fig.add_trace(go.Scatter(y=np.random.randint(20, 40, len(df)), marker_color='#fae823', name='VO', hovertemplate=[]), row=2, col=1)

fig.update_layout({'plot_bgcolor': "#21201f", 'paper_bgcolor': "#21201f", 'legend_orientation': "h"},
                  legend=dict(y=1, x=0),
                  font=dict(color='#dedddc'), dragmode='pan', hovermode='x unified',
                  margin=dict(b=20, t=0, l=0, r=40))

fig.update_yaxes(showgrid=False, zeroline=False, showticklabels=False,
                 showspikes=True, spikemode='across', spikesnap='cursor', showline=False, spikedash='solid')

fig.update_xaxes(showgrid=False, zeroline=False, rangeslider_visible=False, showticklabels=False,
                 showspikes=True, spikemode='across', spikesnap='cursor', showline=False, spikedash='solid')

fig.update_layout(hoverdistance=0)

fig.update_traces(xaxis='x', hoverinfo='none')
fig.show()

尝试

fig.update_layout(hovermode="x unified")

暂无
暂无

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

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