Plotly.py: fill to zero, different color for positive/negative

我的未来我决定 提交于 2019-12-13 03:31:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!