bar chart: textposition='auto' not working for 0 values
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

From the textposition argument documentation for bar traces:
"auto" tries to position
textinside the bar, but if the bar is too small and no bar is stacked on this one the text is moved outside.
For small values this is working nicely: Instead of inside, the text gets positioned outside.
But: For 0 values, the text disappears completely instead of being moved outside.
import pandas as pd
import plotly.express as px
df = pd.DataFrame({
"Country": [f"Country {n}" for n in range(6)],
"Some Metric": [8,5,5,.5,0.0001,0]
})
fig = px.bar(
df,
x='Some Metric',
y='Country',
text='Country',
orientation='h')
fig.update_yaxes(visible=False, showticklabels=False)
# change here between "auto" (default), "inside", "outisde"
fig.update_traces(textposition="auto")
fig.show()
Setting 0 values to a small value is a dirty fix that may also lead to the text disappearing when the graph is resized. At the same time, such a fix endangers data integrity.
The alternative would be setting the textposition for every observation separately. I think that should be avoided and covered by setting texposition="auto".
Fix that everybody can implement in their code currently:
fig.update_traces(textposition=['outside' if val==0 else 'auto' for val in df['Some Metric']])
Tested with plotly 5.10.0.
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
Reproduce el ejemplo de gráfico de barras horizontal con textposition="auto" y un valor cero; después, sigue la ruta de posicionamiento del texto del bar-trace utilizada por Plotly.js. Confirma el comportamiento existente para valores pequeños y define como completado que la etiqueta permanezca visible fuera de la barra cuando su valor sea cero, con cobertura en las pruebas relevantes del bar-trace si están disponibles.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript
- Área
- data-visualization
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Activo
- Claridad
- Bastante claro
- Aptitud para principiantes
- 66/100