Plotly:如何填充线之间的区域?

2024-06-10 15:41:37 发布

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

我在用plotly构建地平线图时遇到了困难。我使用Implementing horizon charts in matplotlib中的演示代码matplotlib.plotly成功地构建了这个函数,但是plotly失败了,因为我在plotly中找不到任何函数来实现fill_between

我想知道如何填充plotly中两条虚线之间的区域


Tags: 函数代码in区域matplotlibplotlybetweenfill
1条回答
网友
1楼 · 发布于 2024-06-10 15:41:37

只需像这样使用fill=tozeroy

绘图:

enter image description here

代码:

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[0, 2, 3],
                         mode = 'lines',
                         fill='tozeroy'))
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[3, 5, 4],
                         mode = 'lines',
                         fill='tonexty'))
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5.5, 6],
                         mode = 'lines',
                         fill='tonexty'))

fig.show()

相关问题 更多 >