How to disable default "(x,y)" within hovertext of go.Bar chart?

Hello, I am creating a chart using fig = go.Figure(data=[go.Bar( and setting hovertext to an array of values, but it still adds the default (x, y) values too. How do I eliminate this? Setting hoverinfo = ‘skip’ or ‘none’ disables the hovertext completely?
Screen Shot 2022-02-28 at 10.37.27 AM

Hello marketemp

Here you have a example:

import plotly.graph_objects as go

x = ['Product A', 'Product B', 'Product C']
y = [20, 14, 23]


layout = go.Layout(hovermode=False)
fig = go.Figure(data=[go.Bar(x=x, y=y)], layout=layout)

# Customize aspect
fig.update_traces(marker_color='rgb(158,202,225)', marker_line_color='rgb(8,48,107)',
                  marker_line_width=1.5, opacity=0.6)
fig.update_layout(title_text='January 2013 Sales Report')
fig.show()

Thanks @SamuelVT. Running this example has no hovertext at all.

I want hovertext. I want the “1-4” in my example that I am defining without the “(9.375, -3)” that is the raw graph data added by default.

Hello marketemp

I hope this can help.

https://plotly.com/python/hover-text-and-formatting/

import plotly.graph_objects as go

x = ['Product A', 'Product B', 'Product C']
y = [20, 14, 23]


layout = go.Layout()
fig = go.Figure(data=[go.Bar(x=x, y=y)], layout=layout)

# Customize aspect
fig.update_traces(marker_color='rgb(158,202,225)', marker_line_color='rgb(8,48,107)',
                  marker_line_width=1.5, opacity=0.6, 
                  hovertemplate = '1-4<extra></extra>',
                  #hovertemplate = 'Price: %{y:$.2f}<extra></extra>',                  
                  )
fig.update_layout(title_text='January 2013 Sales Report')
fig.show()

my code reads:

        fig = go.Figure(data=[go.Bar(
            x=x, y=y, width=width, marker_color=colors, hovertext=hover,
            showlegend=False,
        )])

and I’d rather define the text for each field within my hover list and not use hovertemplate in the layout. There should be a boolean that turns the inclusion of (x, y) off within hovertext.

Hello @mercadoemp

Take a look this:

import plotly.graph_objects as go

x = ['Product A', 'Product B', 'Product C']
y = [20, 14, 23]

# Use the hovertext kw argument for hover text
fig = go.Figure(data=[go.Bar(x=x, y=y,
            hovertext=["Text A", "Text B", "Text C", "Text D", "Text E"],
            hoverinfo="text" )])
# Customize aspect
fig.update_traces(marker_color='rgb(158,202,225)', marker_line_color='rgb(8,48,107)',
                  marker_line_width=1.5, opacity=0.6)
fig.update_layout(title_text='January 2013 Sales Report')
fig.show()

hoverinfo='text' is EXACTLY what I was looking for. Thanks for your help @SamuelVT

1 Like