Funnel plot text does not position itself properly
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- JavaScript
- Estrellas
- 18.3k
- Forks
- 2k
- Merge medio
- 2 d 12 h
- PR fusionados (30 d)
- 28
Descripción
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:

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.
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?
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza reproduciendo el embudo apilado con el ejemplo proporcionado de pandas, plotly.express, update_traces(textposition='auto') y write_image. Sigue cómo el posicionamiento del texto del embudo gestiona las etiquetas Region A y Region B en las etapas más pequeñas; la tarea está terminada cuando las etiquetas mantienen un tamaño legible y coherente, permanecen en el lado correcto y no se solapan ni se salen del gráfico.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, python
- Área
- data-visualization
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Tranquilo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 48/100
