Colorscales in templates are not valid list of lists, which breaks `plotly.colors.sample_colorscale`
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
plotly.colors.validate_colorscale と sample_colorscale から始め、plotly.io.templates が ColorscaleValidator を通じて layout.colorscale の値をどのように公開しているかを追跡します。組み込みの list-of-lists 結果とテンプレートの tuple-of-tuples 結果、および既存の強制変換経路を比較します。テンプレートの colorscale を報告された検証エラーなしで sample_colorscale に渡せるようになれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Hello! I have something which is maybe a bug. It's certainly how I expected plotly.py to work, although maybe it's just a known limitation of how layout templates work.
Plotly comes with various colorscales built in, which work great:
import plotly
rainbow = plotly.colors.get_colorscale("rainbow")
# gives
[[0.0, 'rgb(150,0,90)'],
[0.125, 'rgb(0,0,200)'],
[0.25, 'rgb(0,25,255)'],
[0.375, 'rgb(0,152,255)'],
[0.5, 'rgb(44,255,150)'],
[0.625, 'rgb(151,255,0)'],
[0.75, 'rgb(255,234,0)'],
[0.875, 'rgb(255,111,0)'],
[1.0, 'rgb(255,0,0)']]
This is a list of lists and works as expected: plotly.colors.validate_colorscale(rainbow) passes.
Now I'd like to extract the colorscale from a template. This where things don't work as expected:
diverging = plotly.io.templates["plotly"].layout.colorscale.diverging
# gives
((0, '#8e0152'),
(0.1, '#c51b7d'),
(0.2, '#de77ae'),
(0.3, '#f1b6da'),
(0.4, '#fde0ef'),
(0.5, '#f7f7f7'),
(0.6, '#e6f5d0'),
(0.7, '#b8e186'),
(0.8, '#7fbc41'),
(0.9, '#4d9221'),
(1, '#276419'))
This is a tuple of tuples and does not pass plotly.colors.validate_colorscale(diverging), which raises:
_plotly_utils.exceptions.PlotlyError: A valid colorscale must be a list.
It's easy to convert this into a valid colorscale as diverging = [list(x) for x in diverging] but it seems strange that this is necessary.
Should the colorscale coming from a template be a list of lists already? Or should validate_colorscale accept tuple of tuples as valid? The real reason this matters is because plotly.colors.sample_colorscale runs validate_colorscale under the hood, which raises an error and means that sample_colorscale doesn't work.
Side note
AFAICT there's no way register a new colorscale in plotly other than through a template. plotly.colors.named_colorscales comes from _plotly_utils.basevalidators.ColorscaleValidator.named_colorscales, but that's private and has no method for adding a new scale.
ColorscaleValidator("", "").validate_coerce(diverging) works to do the tuple of tuples to list of lists conversion, but again it's not public, and it seems weird that it would be necessary to run any coercion on a colorscale coming from a template anyway.
- 主要言語
- Python
- スター
- 18.8k
- フォーク
- 2.8k
- 平均マージ
- 13時間 41分
- マージ済み PR(30日)
- 21
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
plotly/plotly.py のほかの issue
-
P3 size: 1 task
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
-
P3 size: 1 task
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug P1
難易度 1/5 1時間未満 初心者へのやさしさ 68/100
-
feature P3
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
feature P3
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
plotly/plotly.py の issue をすべて見る
似ている issue
-
essnmx good first issue
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
-
[Feature] 奇物选择添加优先级 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
syfoud/Simulated_Scepter#174 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Giskard-AI/giskard-oss#2840 · コメント 1 件 ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success オープンarea: repo bug perceived difficulty: 2
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
yeti-platform/yeti#1380 ·