问题
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()
How can I split 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
.
来源:https://stackoverflow.com/questions/57421531/plotly-py-fill-to-zero-different-color-for-positive-negative