question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

px.bar: when base is used, hoverlabel label should be "base+y: %y"

See original GitHub issue

Minimal 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',)

image

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'])])

image

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:open
  • Created 3 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nicolaskruchtencommented, Sep 24, 2020

Still, I wonder why not make it the default behaviour of px.bar(base)

That’s a good idea but the implementation under the hood is a bit more complicated 😃

0reactions
Lxstrcommented, Nov 29, 2022

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?

hoverinfo="text",
hovertext = [f'In stock: {val}' for val in availability_df["InStock"]],

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found