python - 在 Plotly 中在图的底部显示所有子图的迹线值
问题描述
我正在使用 plotly 进行数据可视化。
我生成了一个 3 条轨迹图,它们使用make_subplots
. 我需要通过将鼠标悬停在 x 轴的某处来显示图底部所有迹线的相应 y 值。
下面是生成子图的代码。
import plotly
import plotly.graph_objs as go
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
import re
df = pd.read_csv("finance-charts-apple.csv")
fig = make_subplots(
rows=3, cols=1,
shared_xaxes=True,
vertical_spacing=0.0,
horizontal_spacing = 0.0,
specs=[[{"type": "scatter"}],
[{"type": "scatter"}],
[{"type": "scatter"}]])
fig.add_trace(
go.Scattergl(
x=df.Date,
y=df['AAPL.High'],
mode="lines",
name="AAPL_high"
),
row=1, col=1
)
fig.add_trace(
go.Scattergl(
x=df.Date,
y=df['AAPL.Low'],
mode="lines",
name="AAPL_low"
),
row=2, col=1
)
fig.add_trace(
go.Scattergl(
x=df.Date,
y=df['AAPL.Close'],
mode="lines",
name="AAPL_Close"
),
row=3, col=1
)
fig.update_layout(
height=800,
showlegend=True,
title_text="Apple market share",
hovermode= 'x unified',
hoverinfo= "x+y",
spikedistance= -1,
xaxis = dict(
showspikes = True,
spikemode = 'across + toaxis',
spikesnap = 'cursor',
showline= True,
showgrid = True,
spikedash = 'solid'))
fig.update_xaxes(matches='x')
fig.update_traces(xaxis='x1')
fig.show()
plotly.offline.plot(fig)
根据上面的代码,我可以在所有子图中垂直悬停绘制 3 个子图。
我想知道的是,有没有办法在图的底部显示每个轨迹的特定 x 值的 y 值,如下图所示?
解决方案
截至 2020 年 7 月 21 日,hovermodes
尚未对 plotly subplots (v4.4.x) 实施统一。
在他们的 js 存储库中,这个特性存在一个未解决的问题,但它是对所有发行版的有效请求。您可以在https://github.com/plotly/plotly.js/issues/4755订阅它。
推荐阅读
- c# - 我希望字符串包含特定的字符
- azure - 如何解决“DNS 区域没有足够的标签通过 PowerShell”错误
- php - 将此作为维度数组
- c# - 如何只对一个对象使用属于两个对象的一个函数?
- python - Python pyplot 图例散点图
- typescript - 如何扩展DefinitelyTyped社区定义的函数声明?
- swift - Swift 数字格式器货币问题
- sql-server - SQL Server:添加具有相同列的行/表
- python - 如何在一定时间后使文本消失?
- android - 使用 startActivityForResult 时 AutocompleteActivity 抛出 IllegalStateException