Bring Drag & Drop to Dash with Dashboard Engine. 💫 Learn how at our next webinar!

Px.line() adding extra linear faded/dashed lines all over plot

Hello. I have a DataFrame with a unique ID tag for the data for multiple lines.

When I use px.line(data, x=data[‘x’], y=data[‘y’], color=data[‘line_id’]), a plot is produced with the lines correctly separated, but each line also is associated with some extra faded/dashed line in the background. This is shown below.

I have checked that I have sorted by data correctly, so that is not the problem. I have also tried creating this plot using a method where I loop through the 'line_id’s and add them to a go.Figure() with a go.Scatter() trace one-by-one, and this works with no issue, but of course is not as efficiently. How the plot is supposed to look using this method is shown below.

Is there any fix to this issue such that I can use px.line()? Or is there something else I am doing incorrectly? I have checked with the examples on the Line Chart Plotly page, and that works totally fine, so I am just unclear what could possibly be going on.

Thank you!

I’m not sure if this will fix your issue, but (I’m pretty sure) your call to px.line should look like this: px.line(data, x='x’, y=‘y’, color=‘line_id’)

Try that and see if it helps.

Yes, you are absolutely right, sorry I mistyped that in my question, but I have been doing it correctly in my script like you said, and unfortunately it does not help!

I have used px.line with great success, so I feel there may be something else in you usage of px.line that may be causing this. Could you paste the exact px.line command that you use?

Also, another important thing to consider is that this issue may be caused by the data in your data frame. I may not know exactly what I’m talking about, but my intuition tells me that plotly is just plotting the data in your column, and perhaps you need to clean up the data a little before it is ready to be plotted.