问题
With Plotly, I can easily plot two lines and fill the area between them:
import plotly.graph_objects as go
fig = go.Figure()
fig.add_trace(go.Scatter(
x=[1, 2, 3, 4],
y=[-1, -.2, 1, 2],
fill=None,
mode='lines',
))
fig.add_trace(go.Scatter(
x=[1, 2, 3, 4],
y=[-1, -.5, 0.2, .5],
fill='tonexty',
mode='lines',
))
fig.update_layout(title_text='hello world')
fig.show()
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. While maintaining the fill only between the lines.
I would like to maintain the line colors and legend. That means, I am not interested in just drawing two separate filled pollygons.
Note that the lines do not necessarily have values at y == 0.
来源:https://stackoverflow.com/questions/57421334/plotly-py-fill-between-lines-different-color-por-positive-negative