plotly / plotly.py

The interactive graphing library for Python :sparkles: This project now includes Plotly Express!
https://plotly.com/python/
MIT License
16.06k stars 2.54k forks source link

textposition="auto" doesn't show texts for 0 values #4686

Open chaosink opened 2 months ago

chaosink commented 2 months ago
import pandas as pd
import plotly.graph_objects as go

df = pd.DataFrame(
    {
        "A": [5, 0, 7],
        "B": [5, 0, 7],
    },
    index=[1, 2, 3],
)

fig = go.Figure(
    data=[
        go.Bar(
            name="A",
            x=df.index,
            y=df["A"],
            text=df["A"],
            textposition="auto",
        ),
        go.Bar(
            name="B",
            x=df.index,
            y=df["B"],
            text=df["B"],
            textposition="outside",
        ),
    ]
)

fig.update_layout(
    xaxis_title=None,
    yaxis_title=None,
    legend_title=None,
)

fig.show()

newplot

archmoj commented 2 months ago

I'm not sure we should consider this a bug. Here is a codepen illustrating the graph using plotly.js. You could use an array to specify desirable textposition as illustrated in this codepen.

gvwilson commented 2 months ago

@chaosink I agree with @archmoj that this is a feature rather than a bug - may I close the issue?