Scatterplot Lines, Unwanted Connecting

Hello all,

I have an issue which I just can’t seem to figure out.

I have a plot like this:

… and I’ve created a log-log model in an external script.

When I add a Scatter trace to the data, I get a bunch of unwanted line connections:

I’m creating the trace like this:

curve = go.Scatter(
    x=sl.population,
    y=sl.fit,
    marker=go.Marker(color='red'),
    name='Fit',
    line=dict(shape='spline')
)

Where sl is a Pandas DataFrame.

And the scatter points line this:

scatter = go.Scatter(                                                        
    x=sl.population,                                                                    
    y=sl.y,                                                                    
    mode='markers',                                                         
    marker=go.Marker(color='#3D3C28'),                                      
    name=ylab,                                                              
    hoverinfo=hoverinfo,                                                    
     text=names,                                                             
)

I’m passing these values into a function which I use regularly to create a scatterplots like the ones shown here but with linear trendlines.

So the straighline version of the model works fine, but for some reason I’m having trouble overlaying non-linear curves…

So, how do I create a plot like the one below, but with a red line instead of a series of red dots?

3 Likes

Hi, I am also facing this issue. Did you find any workaround for this?

Hi @sureshj and @dasenbrj,

This behavior can happen if the rows in the DataFrame aren’t sorted by their x-axis value. The ordering doesn’t affect the appearance of scatter markers, but lines are drawn based on the ordering of the input vectors.

-Jon

4 Likes

Thanks @jmmease ; It resolved the problem.

1 Like

Hi @jmmease
Please I’m Facing the same problem even if my x_axis value are sorted.
the problem is when plotting multiple traces, if I select just one trace it will be ok, but once all traces are selected the behaviour will change.
CAN YOU HLEP ?

Thank you,

I found this happening whenever one of my series wasn’t complete, as in it was missing data points across the x-axis that other series had. The plot would behave as expected until the series with missing data is added in.

1 Like

This worked for me. Cheers