Colorscales in templates are not valid list of lists, which breaks `plotly.colors.sample_colorscale`
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 42/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- python
- Bereich
- data-visualization
Rechercherichtung
Beginne mit plotly.colors.validate_colorscale und sample_colorscale und verfolge anschließend, wie plotly.io.templates die layout.colorscale-Werte über ColorscaleValidator bereitstellt. Vergleiche das integrierte list-of-lists-Ergebnis mit dem tuple-of-tuples-Ergebnis des Templates und dem bestehenden Koerzierungspfad; als erledigt gilt die Aufgabe, wenn Template-Farbschemata ohne den gemeldeten Validierungsfehler an sample_colorscale übergeben werden können.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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.
- Vorherrschende Sprache
- Python
- Sterne
- 18.8k
- Forks
- 2.8k
- Ø Merge
- 13 Std. 41 Min.
- Gemergte PRs (30 T.)
- 21
Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus plotly/plotly.py
-
P3 size: 1 task
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
P3 size: 1 task
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
bug P1
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 68/100
-
feature P3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 62/100
-
feature P3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Alle Issues in plotly/plotly.py
Ähnliche Issues
-
enhancement
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
canonical/paas-charm#368 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
tech debt
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
StevenBlack/hosts#3256 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 90/100
qualcomm/qai-appbuilder#275 ·