Add continuous color scale to strip, box, and violin plots
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 18.8k
- Fork
- 2.8k
- Merge medio
- 16h 26m
- PR unite (30g)
- 21
Descrizione
Currently, strip/box/violin plots only work with categorical/discrete colormaps. This is sufficient for the violins and boxes but for the points that can be included in all three plots, it would be useful to color by a continuous feature and to add a colorbar to the plot. I looked around a bit and it seems like the go.Box constructor needs to have the coloraxis attrbute added to it (and I suspect something would need to be added to avoid coloring the boxes/violins in the same colors as the points, since they are colored the same for categorical variables).
The example below illustrates the issue by trying to color by the sepal_width variable:
import plotly.express as px
iris = px.data.iris()
px.strip(iris, 'species', 'sepal_length', 'sepal_width', stripmode='overlay')

The resulting plot is not meaningful since it colors a continuous variable with a discrete colormap.
So far, I have not found a prettier workaround that this (which is imperfect since it uses the legend instead of a colorbar):
import matplotlib as mpl
sw = iris['sepal_width'].sort_values()
sw_01 = (sw - sw.min()) / (sw.max() - sw.min())
sw_colors = {n: mpl.colors.rgb2hex(c) for n, c in zip(sw, mpl.cm.viridis(sw_01))}
px.strip(iris, 'species', 'sepal_length', 'sepal_width',
stripmode='overlay', category_orders={'sepal_width': sw.to_list()[::-1]},
color_discrete_map=sw_colors)

Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con px.strip e il costruttore go.Box, concentrandoti su come i grafici strip, box e violin gestiscono attualmente i colori categoriali. Riproduci l’esempio iris usando sepal_width come caratteristica del colore, quindi traccia come vengono assemblati l’attributo coloraxis e la colorbar del grafico. Il lavoro è completato quando la colorazione continua e una colorbar funzionano per i punti inclusi senza applicare erroneamente i colori dei punti ai box o ai violini.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- data-visualization
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100