How to DO NOT fill area under NaN in plotly
Asked Answered
C

1

8

Ciao all,

I am working with plotly.

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.

Please notice that in my case 0 and NaN are different so that setting NaN to 0 is a solution for the area issue that does not fit in my case.

I tried with the following code:

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)

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.

enter image description here

I'd like to reach this result:

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)

enter image description here

(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?

Thanks

am

Cristoforo answered 17/10, 2019 at 14:0 Comment(0)
P
1

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

Pirate answered 18/10, 2019 at 2:19 Comment(4)
Ciao, it doesn't work form me. I'm working on python 2.7. My plotly version is 3.7.0. Does it work for you? If yes which plotly version are you using? Thx!Cristoforo
Ah, sorry, my mistake: this is still an open issue github.com/plotly/plotly.js/issues/3244Pirate
Has this been solved ?Adal
@Adal Nope, I am now using python3 and it's not working (plotly==5.4.0)Cristoforo

© 2022 - 2024 — McMap. All rights reserved.