如何在绘图中不填充 NaN 下的区域 [英] How to DO NOT fill area under NaN in plotly

查看:23
本文介绍了如何在绘图中不填充 NaN 下的区域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在与情节合作.

我需要画一条曲线并填充它下面的区域.可能会出现一些 NaN,在这种情况下不填充区域非常重要.

I need to draw a curve and fill the area under it. It could be some NaNs appear and it is very important that in that case area is not filled.

请注意,在我的情况下 0 和 NaN 是不同的,因此将 NaN 设置为 0 是解决我的情况不适合的区域问题的解决方案.

我尝试了以下代码:

import plotly.graph_objs as go
from plotly.offline import plot

p = go.Scatter(x=range(0,12),
           y = [1,2,3,np.nan, np.nan, np.nan, np.nan, np.nan, 0,0,0,5],
           fill='tozeroy')
fig = go.Figure([p])
plot(fig, auto_open=True)

但我得到了一个我不喜欢的结果.如您所见,没有对应于 NaN 的点,因此在悬停模式下不会显示任何内容(我喜欢它!)但是有区域.

but I get a result I do not like. As you can see there are no points corresponding to the NaN, so that nothing will be displays in the hovermode (I like it!) but there is the area.

我想达到这个结果:

import plotly.graph_objs as go
from plotly.offline import plot

p1 = go.Scatter(x=range(0,3),
           y = [1,2,3],
           fill='tozeroy')
p2 = go.Scatter(x=range(8,12),
           y = [0,0,0,5],
           fill='tozeroy')

fig = go.Figure([p1, p2])
plot(fig, auto_open=True)

(当然我希望图例中只有一种颜色和一个元素.)

(Of course I'd like the plot to have only one color and only one element in the legend.)

你能帮我重现第二个图而不把曲线分成多条曲线吗?

Can you help me to reproduce the second plot without splitting the curve in multiple curves?

谢谢

上午

推荐答案

已我认为目前没有办法对区域执行此操作,尽管它确实适用于线条.这是未解决的问题:https://github.com/plotly/plotly.js/问题/3244

Edited: I don't believe there is currently a way to do this with areas, although it does work for lines. Here is the open issue: https://github.com/plotly/plotly.js/issues/3244

这篇关于如何在绘图中不填充 NaN 下的区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆