plotly / plotly/plotly.py

`labelalias` in `Scatter.marker.colorbar` can't handle negative values

Open
#4,924 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I am building a line-chart, which uses a colorgradient. The values of the line chart can be negative and positive. I want to add a colorbar to explain the meaning of the colors in the gradient. For this I use labelalias. The labels only appear for ticks >= 0.

Example

trace = go.Scatter(
  x = x,
  y = y,
  marker = dict(
    color=y,
    colorscale=[(0.0, "royalblue"), (0.5, "rgba(230, 230,230,0.5)"), (1.0, "orange") ]
    colorbar=dict(
                title="Score",
                tickmode="array",
                tickvals=[-10, 0, 10],
                labelalias={-10: "Negative", "0": "Neutral", 10: "Positive"},
                ticks="",
    )
  )
)

The output looks like this:
Image

Expected behavior

The label -10 is replaced by Negative

Context
  • python==3.11
  • plotly==5.24.1

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 reproducing the Python example from the issue with Scatter.marker.colorbar, tickvals=[-10, 0, 10], and the supplied labelalias mapping. Trace how negative tick aliases are handled and verify that the completed change replaces the -10 tick label with "Negative" while preserving the other labels.

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
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.