Non-solid lines display distorted

Hi everyone,

I’m using Plotly (v 6.0.0) for a project at work and have run into the issue of dotted/dashed lines being distorted in any plot that isn’t purely linear (see image below).

I’m applying the style change using the Figure.update_traces() function, and the figure is a layout of subplots. The figure is displayed in a Panel widget for the project, but I get the same behavior in my IDE (PyCharm) when calling Figure.show() and when saving the image from the mode bar.

Has anyone run into this before or have tips for how to avoid it? Thanks in advance!

Hey @c8eh welcome to the forums.

Does this occur with plotly < 6.0.0? Could you provide the code for this chart?

The behavior occurs with plotly >= 5.17.0 (earliest version that supports all of the options I use for this chart).

More digging leads me to believe that the problem occurs when points along the line are tightly spaced (or there is simply high curvature). The tool I am creating is intended to be used to plot data from files with potentially varying intervals between data samples.

I apologize for the delay in producing a MWE. My project is a larger application, so it has taken some effort to distill down. Here is trimmed-down version of my project:

# Core modules
import math

# Non-core modules
import polars as pl
import plotly.graph_objs as go

if __name__ == "__main__":
    df = pl.DataFrame({"x": [x * 0.05 for x in range(0, 201)]})
    # display seems to be distorted with small intervals between data points
    # exponential:
    df = df.with_columns(y6=pl.col("x").exp() / 1000)
    # linear with same ending value:
    df = df.with_columns(y1=(pl.col("x") * (math.exp(10) / 10 / 1000)))
    # gradually becomes "more exponential":
    df = df.with_columns(y2=pl.col("y1") + ((pl.col("y6") - pl.col("y1")) * 0.2))
    df = df.with_columns(y3=pl.col("y1") + ((pl.col("y6") - pl.col("y1")) * 0.4))
    df = df.with_columns(y4=pl.col("y1") + ((pl.col("y6") - pl.col("y1")) * 0.6))
    df = df.with_columns(y5=pl.col("y1") + ((pl.col("y6") - pl.col("y1")) * 0.8))

    fig = go.Figure()
    for j, y in enumerate(["y1", "y2", "y3", "y4", "y5", "y6"]):
        fig.add_trace(
            go.Scattergl(
                x=df.get_column("x"),
                y=df.get_column(y),
                mode="lines",
                line=dict(dash="dot"),
            ),
        )
    fig.show()

Thank you for the MWE, I appreciate the effort!. I tried this on my side, the graph looks like that:

Not sure if the issue is visible here, could you confirm that? plotly v6.0.0

I can see the issue, but it isn’t nearly as bad as I’ve seen before. Making the plot narrower (for me, resizing the window works) should make it appear worse. Zooming out can also exaggerate it.