Bug when using categorical axes and colors in plotly.express
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 18.8k
- Forks
- 2.8k
- Ø Merge
- 16 Std. 26 Min.
- Gemergte PRs (30 T.)
- 21
Beschreibung
According to the documentation:
By default, Plotly Express lays out categorical data in the order in which it appears in the underlying data.
However, when using categorical axes in conjunction with colors, things do not show up in the order of the underlying data anymore.
import plotly.express as px
pdata_x = ["A","B",None,"B","C",None,"C","D", None, "D", "E", None]
pdata_y = [1,1,None,2,2,None,3,3,None,4,4,None]
pdata_color = [1,1,1,2,2,2,2,2,2,1,1,1]
px.line(x=pdata_x, y=pdata_y, color=pdata_color).show()
Output is

When not(!) using colors, we would get the correct output:
px.line(x=pdata_x, y=pdata_y ).show()

For anyone who comes across this problem, a temporary fix is explicitely specifying the category order:
px.line(x=pdata_x, y=pdata_y, color=pdata_color, category_orders={"x":["A","B","C","D"]}).show()

plotly==4.14.3
Python 3.8.0 (default, Feb 25 2021, 22:10:10)
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Führe zunächst das bereitgestellte Python- und plotly.express px.line-Beispiel mit kategorialen x-Werten und Farben aus und vergleiche es anschließend mit den Fällen ohne Farbe und mit explizitem category_orders. Verfolge, wie die Reihenfolge von Kategorien für farbige Linien bestimmt wird. Erledigt ist die Aufgabe, wenn die Standardreihenfolge den zugrunde liegenden Daten folgt, auch wenn color verwendet wird, während der dokumentierte Workaround mit expliziter Reihenfolge weiterhin funktioniert.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- data-visualization
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100