Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉 適合新手
#5,805 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@MokiMeow 已經在處理了。

開始於 2026年10月10日。

  • #5806 來自 @MokiMeow —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
82/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python

研究方向

問題出在 plotly.colors 輔助函式 sample_colorscale 和 n_colors,兩者都除以所要求的數量減一。請先執行 issue 中的重現腳本,確認數量為 1 時會拋出 ZeroDivisionError。當要求單一顏色時,回傳區間起點(low / lowcolor)處的一個顏色,與多顏色情況的第一個取樣結果一致,且零顏色的情況仍回傳空列表,即為完成。

由索引模型根據 Issue 內容生成。

描述

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.

主要語言
Python
星號
18.8k
分支
2.9k
平均合併
3 天 7 小時
30 天內合併 PR
20

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

plotly/plotly.py 的其他 Issue

查看 plotly/plotly.py 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。