Garvey
Garvey

Reputation: 1309

Plotly: How to fill area between lines?

I meet difficult in building horizon graph with plotly. I succeed in building this with matplotlib.plotly using demo code from Implementing horizon charts in matplotlib, but fail with plotly because I couldn't find any function to achieve fill_between in plotly.

I am wondering how to fill an area between two broken line in plotly.

Upvotes: 4

Views: 9114

Answers (1)

vestland
vestland

Reputation: 61084

Just use fill=tozeroy like this:

Plot:

enter image description here

Code:

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()

Upvotes: 5

Related Questions