Repository navigation
bar chart: textposition='auto' not working for 0 values #6474
Description
Activity
Duplicate of plotly/plotly.py#2709
- marked this as a duplicate of textposition='auto' not showing zero values plotly.py#2709
on Feb 8, 2023 @archmoj is this by design? I noticed this in
bar/plot.js:if(!text || textPosition === 'none' || ((calcBar.isBlank || x0 === x1 || y0 === y1) && ( textPosition === 'auto' || textPosition === 'inside'))) { bar.select('text').remove(); return;
plotly.js/src/traces/bar/plot.js
Lines 301 to 307 in 70c49ce
if(!text || textPosition === 'none' || ((calcBar.isBlank || x0 === x1 || y0 === y1) && ( textPosition === 'auto' || textPosition === 'inside'))) { bar.select('text').remove(); return; Does look like a bug to me, and certainly a zero-size bar is different from no bar! Nice detective work @AaronStiff - fixing this may be as simple as removing that
textPosition === 'auto' ||line (and adding this situation to a test image) but it would be good to at least investigate why that condition was added in the first place...Thanks @alexcjohnson! Unfortunately I'm not really setup for/knowledgeable in plotly.js development yet, so I'll let someone else make that change. But the git blame seems like it's been around for several years.
Also in the same position of having to conside that same dirty fix for 0 values! 🙏
- marked BUG: 0 and small values aren't displayed on Bar Chart when
textpositionis set toauto#6544 as a duplicate of this issueon Aug 28, 2026 Codepen from duplicate issue #6544: https://codepen.io/bleah1/pen/dyqLmvN
Equivalent plotly.py issue: plotly/plotly.py#4686
From the textposition argument documentation for bar traces:
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.
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
textpositionfor every observation separately. I think that should be avoided and covered by settingtexposition="auto".Fix that everybody can implement in their code currently:
Tested with
plotly 5.10.0.