plotly / plotly/plotly.py

Incorrect legend style with x unify hovermode

Open
#4,882 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hello

I noticed that something is incorrect with the legend styling, especially when we use the x unify hovermode.

Here is a short example:

import plotly.graph_objects as go

x = ["A", "B"]
fig = go.Figure(data=[
    go.Bar(
        x=x, 
        y=[1, 1],
        marker=dict(color=["blue", "red"], pattern_shape=["/", ""]),
        name="First Bar"
    ),
    go.Bar(
        x=x, 
        y=[-1, -1],
        marker=dict(color=["green", "purple"], pattern_shape=["/", ""]),
        name="Second Bar",
    ),
])

fig.update_layout(hovermode="x unified")
fig.show()

Image

As we can see, the second bar uses the "general" legend style, which leads to an incorrect style for the items on the right.
plotly version = 5.24.1

And thank you for your amazing work!

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

Start by running the provided Python example with plotly.py 5.24.1 and compare the legend styling for both bars when hovermode is set to "x unified". Trace the legend rendering entry point and add a regression check showing that the second bar's legend items use the correct style.

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
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.