Open
Description
Whenever a graph object has the following parameters:
First series -> fill='tonexty',
Second series -> connectgaps=False
The fill connects the first point of this series with the first point of the last segment after "gaps" from the second series, instead of its respective first value.
Here is a basic example
import plotly.graph_objects as go
fig = go.Figure()
def remove_from_list(lst, idx):
return lst[:idx] + [None] + lst[idx+1:]
x = [i for i in range(5)]
y = [1 for _ in x]
fig.add_trace(go.Scatter(
x=x,
y=remove_from_list(y, 2),
connectgaps=False
))
y = [2 for _ in x]
fig.add_trace(go.Scatter(
x=x,
y=y,
fill='tonexty',
))
fig.show()
Here is another example with more than 1 gap in the data:
import plotly.graph_objects as go
fig = go.Figure()
def remove_from_list(lst, idx):
return lst[:idx] + [None] + lst[idx+1:]
x = [i for i in range(8)]
y = [1 for _ in x]
fig.add_trace(go.Scatter(
x=x,
y=remove_from_list(remove_from_list(y, 2), 5),
connectgaps=False
))
y = [2 for _ in x]
fig.add_trace(go.Scatter(
x=x,
y=y,
fill='tonexty',
))
fig.show()
I've also attached their respective figure outuputs.
Finally, I have an additional comment regarding how areas are filled.
The following shows another basic example with gaps in both series, and both with connectgaps=False.
import plotly.graph_objects as go
fig = go.Figure()
def remove_from_list(lst, idx):
return lst[:idx] + [None] + lst[idx+1:]
x = [i for i in range(5)]
y = [1 for _ in x]
fig.add_trace(go.Scatter(
x=x,
y=remove_from_list(y, 2),
connectgaps=False
))
y = [2 for _ in x]
fig.add_trace(go.Scatter(
x=x,
y=remove_from_list(y, 2),
fill='tonexty',
connectgaps=False
))
fig.show()
The connected area spans even the places where the values are undefined (during a gap). My expectation would be the opposite: