Plotly.py: fill to zero, different color por posit

2019-08-17 07:54发布

With Plotly, I can easily plot a single lines and fill the area between the line and y == 0:

import plotly.graph_objects as go

fig = go.Figure()
fig.add_trace(go.Scatter(
    x=[1, 2, 3, 4],
    y=[-2, -1.5, 1, 2.5],
    fill='tozeroy',
    mode='lines',
))
fig.show()

enter image description here

How can I make it to separate the filled area in two? In particular, filling with red where y < 0 and with green where y > 0.

I would like to maintain the line as continuous. That means, I am not interested in just drawing two separate filled polygons.

Note that the line does not necessarily have values at y == 0.

0条回答
登录 后发表回答