Skip to content

Incorrect fill in graph objects when connectgaps is set to false #5105

Open
@NoniosTheMad

Description

@NoniosTheMad

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

Image

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

Image

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:
Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2considered for next cyclebugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions