plotly / plotly/plotly.py

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

Open
#4,588 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug P3 sev-3
Dominant language
Python
Stars
18.8k
Forks
2.8k
Avg merge
16h 26m
Merged PRs (30d)
21

Description

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



Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the provided minimal working example with four subplots and compare the rendering with and without the LaTeX legend name. Trace how subplot x-axis coordinates are computed during rendering, then verify that all subplot positions remain aligned when the secondary-axis trace uses the LaTeX label.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.