plotly / plotly/plotly.py

Order of marginal wrong when using facet_col and setting traces to invisible by default

Offen
#4,438 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P3
Vorherrschende Sprache
Python
Sterne
18.8k
Forks
2.8k
Ø Merge
16 Std. 26 Min.
Gemergte PRs (30 T.)
21

Beschreibung

I am creating a histogram plot using plotly express.histogram, like the following:

df = pd.DataFrame({
    'month': [5] * 30 + [6] * 30 + [7] * 30,
    'value': np.random.randint(0, 100, size=90),
    'Module': ['M', 'P']*45,
})

fig = px.histogram(
    df,
    x='value',
    opacity=0.8,
    color='month',
    category_orders={'month': df['month'].sort_values(ascending=True)},
    marginal='box',
    barmode='overlay',
    facet_col='Module',
)

for trace in fig.data:
    if int(trace.name) not in (7,6):
        trace.visible = "legendonly"

fig.show()

When I then want to show month 5 as well, the box in marginal is placed at the top of the others, giving the wrong order of month: 5, 7, 6 (red from top to bottom).

The problem does not appear when I don't use the facet_col argument, or when i show all month from the beginning (simply comment the part where i set trace.visible to legendonly).

plotly version: 5.18.0

Screenshot 2023-11-22 153608

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, das bereitgestellte plotly.express.histogram-Beispiel mit plotly 5.18.0 auszuführen, und vergleiche das Verhalten von facet_col und marginal, wenn die Traces auf legendonly gesetzt sind beziehungsweise alle Traces sichtbar sind. Verfolge, wie die Reihenfolge der marginalen Boxen erzeugt wird, und überprüfe, dass das Einblenden von Monat 5 die Kategorienreihenfolge 5, 6, 7 beibehält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
data-visualization
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.