Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[BUG]: Single-color requests raise ZeroDivisionError in palette helpers

Open Beginner friendly
#5,805 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@MokiMeow is already working on this.

Since Oct 10, 2026.

  • #5806 by @MokiMeow — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python

Research direction

The bug is in the plotly.colors helpers sample_colorscale and n_colors, which both divide by the requested count minus one. Start by running the reproduction script in the issue to confirm the ZeroDivisionError for a count of 1. Done when a single-color request returns one color at the start of the interval (low / lowcolor), matching the first sample of the multi-color case, and the zero-color case still returns an empty list.

Written by the indexing model from the issue text.

Description

Description

sample_colorscale and n_colors raise ZeroDivisionError when asked for one color. This breaks palettes sized to a dataset's group count when there is exactly one group. Both helpers divide by the requested count minus one.

Expected: one color from the start of the interval (low / lowcolor), consistent with their existing first sample.

Screenshots/Video

The API calls fail before a figure can be created; the output is shown below.

Steps to reproduce
from plotly.colors import n_colors, sample_colorscale

for label, call in [
    ("sample_colorscale", lambda: sample_colorscale("Viridis", 1)),
    ("n_colors", lambda: n_colors((0, 0, 0), (1, 1, 1), 1)),
]:
    try:
        print(label, call())
    except ZeroDivisionError as error:
        print(label, type(error).__name__, str(error))

Actual:

sample_colorscale ZeroDivisionError division by zero
n_colors ZeroDivisionError float division by zero

Expected:

sample_colorscale ['rgb(68, 1, 84)']
n_colors [(0.0, 0.0, 0.0)]
Notes

Reproduced with Plotly 7.1.0, current main 3f8a650930feadfdb651cd869ffe3e85fd093885, Python 3.12.10, Windows amd64. Zero-color requests already return empty lists.

Dominant language
Python
Stars
18.8k
Forks
2.9k
Avg merge
3d 7h
Merged PRs (30d)
20

Getting set up

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.

More from plotly/plotly.py

All issues in plotly/plotly.py

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.