plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Adding secondary-y latex legend name shifts x-axis coordinates

Open cmgoold opened this issue 10 months ago • 0 comments

Plotly version 5.20.0.

I am creating subplots with seconary y-axes. When I add the name attribute to a figure that includes a Latex string, the x-axis coordinates are incrementally shifted more and more to the right with each subplot. For instance, the first subplot in this image renders fine, but 2 through 4 are shifted right:

newplot (26)

This only happens when including the Latex string.

Here's a minimal working example:

import plotly.graph_objects as go
from plotly.subplots import make_subplots

x = [1, 2, 3, 4]
y = [1]*4

R = 1
C = 4

fig = make_subplots(
    rows=R,
    cols=C,
    specs=[
        [{"secondary_y": True} for _ in range(C)]
        for _ in range(R)
    ],
)

rc = [(r, c) for r in range(R) for c in range(C)]

for i, (r, c) in enumerate(rc):
    fig.add_trace(
        go.Scatter(
            x=x,
            y=y,
            showlegend=not i,
            name="y1",
        ),
        row=r+1,
        col=c+1,
        secondary_y=False,
    )
    fig.add_trace(
        go.Scatter(
            x=x,
            y=y,
            showlegend=not i,
            name=r"$y$2",
        ),
        row=r+1,
        col=c+1,
        secondary_y=False,
    )



cmgoold avatar Apr 25 '24 10:04 cmgoold