px.bar: when base is used, hoverlabel label should be "base+y: %y"
See original GitHub issueMinimal example:
tasks = pd.DataFrame([
dict(Task="A", Start=0, Elapsed=10),
dict(Task="B", Start=0, Elapsed=5),
dict(Task="C", Start=5, Elapsed=10)
])
px.bar(tasks, base='Start', y='Elapsed', text='Task',)
Imagine an horizontal gantt-chart where x=Elapsed
is Task duration in days. The issue is that Task C has “Elapsed=15” instead of “Elapsed=10”.
This also an issue in the graph_objects
API in the default hover, but at least adding x as text shows the proper one.
go.Figure(data=[go.Bar(base=tasks['Start'], y=tasks['Elapsed'], text=tasks['Elapsed'])])
Note: In px.timeline
it’s fine since user must give Finish=
but in px.bar
it’s looks pretty misleading to “change” x into finish 😃
If my Task lasts 10 days, the fact that it ends at day 15 is an internal positioning detail.
@nicolaskruchten is it just an oversight from https://github.com/plotly/plotly.py/issues/2585 or do you intend it this way?
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Hover text and formatting in Python - Plotly
How to use hover text and formatting in Python with Plotly. ... If layout.hovermode='x' (or 'y' ), a single hover label appears per...
Read more >Plotly Express Bar chart (px.bar) labels option doesn't override ...
I'm trying to override the default legend labels in px.bar. Am I doing this correctly?
Read more >plotly.express package — 5.11.0 documentation
Values from this column or array_like are used to size y-axis error bars. If error_y_minus is None , error bars will be symmetrical,...
Read more >Taking Another Look at Plotly - Practical Business Python
To demonstrate, we will use some cereal data that I cleaned up for ... the rating and sugars and include the cereal name...
Read more >Hover Text and Formatting in Python-Plotly - GeeksforGeeks
In this article, we will explore how to Hover Text and Formatting in ... If layout.hovermode='y' , a single hover label appears per...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That’s a good idea but the implementation under the hood is a bit more complicated 😃
So the required code in the end works but removes all label text on the actual bars 😞 Is there any way to keep the labels on the bars?
I also had to remove this line
fig.update_traces(hovertemplate="%{x}")
I also wonder is this the most effective and CPU efficient way to do it? I feel like these lines to replicate what could be default seems unusual?
Ref: https://dev.to/fronkan/stacked-and-grouped-bar-charts-using-plotly-python-a4p