plotly / plotly/plotly.js

Funnel plot text does not position itself properly

Offen
#7,756 7 Kommentare 6 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug P3
Vorherrschende Sprache
JavaScript
Sterne
18.3k
Forks
2k
Ø Merge
2 T. 12 Std.
Gemergte PRs (30 T.)
28

Beschreibung

I'm attempting to produce a stacked funnel plot of activities. The labels are not appearing as expected on the plot.

I'm reposting my question from Stack Overflow here based on the response I got there indicating this might be a bug and it would be of interest here. I did not see a duplicate while searching GitHub.


First my code:

import pandas as pd
import plotly.express as px

stages = ["Initial Landing", "Step 2", "Step 3", "Added to cart", "Purchased"]
regiona_plotly = pd.DataFrame(dict(number=[10866,10543,1067,1032,108], stage=stages))
regionb_plotly = pd.DataFrame(dict(number=[10650,10432,1076,1036,1012], stage=stages))
regiona_plotly['region'] = "Region A"
regionb_plotly['region'] = "Region B"
df = pd.concat([regiona_plotly, regionb_plotly], axis=0)
fig = px.funnel(df, x='number', y='stage', color='region')
fig.update_traces(textposition='auto')
fig.update_layout(autosize=True)
fig.write_image("region_funnel.png")

(Lifted almost entirely from plotly documents)

This code produces an image like so:
Plotly - Auto Text Position

Notice that on "Step 3", "Added to cart", and "Purchased" the region A text is scaled very small and inside the bar, but Region B is outside.

I tried updating this line:

fig.update_traces(textposition='outside')

But, with this, I get both values overlapping on the Region B side of the funnel. Also, the text goes outside of the plot on the upper bands.

Plotly - Outside Text Position

How can I get text to be the same size and either be within the bar if it fits at the size or outside and on the correct side, if it doesn't?

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

Beginnen Sie damit, den gestapelten Funnel mit dem bereitgestellten Beispiel für pandas, plotly.express, update_traces(textposition='auto') und write_image zu reproduzieren. Verfolgen Sie, wie die Positionierung des Funnel-Texts die Bezeichnungen Region A und Region B bei kleineren Stufen behandelt; abgeschlossen ist die Aufgabe, wenn die Bezeichnungen eine konsistent lesbare Größe behalten, auf der richtigen Seite bleiben und sich nicht überlappen oder den Plot verlassen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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