Remove hover data in plotexpress

Dear all,
I’m trying to remove some of the displayed data from hover but since the data is a list, I’m having trouble, and I would appreciate some help. (Note: “n_ing_ead” and the others are just numbers)
Thanks, in advance!
Here is my code:

import plotly.express as px
import plotly.graph_objects as go


fig = px.bar(x = ['Ensino EAD', 'Ensino presencial', 'Total'],
             y = [n_ing_ead, n_ing_pres, n_ing],
             hover_name=['Ingressante no ensino EAD', 'Ingressante no ensino presencial', 'Total'],
             color=['EAD','Presencial','Total'],
             labels={'x':'Ingressantes','y':'NĂşmero de ingressantes'}, height=500, width = 500)


fig.layout.update(showlegend=False)
fig.show()

and here is a figure of what I want to remove (the “color=EAD” and “Ingressantes=Total” should be gone from all three bars
Screenshot from 2022-09-14 18-06-16

1 Like

Hi @SirTales and welcome to the community!
If you load you’re data into a dataframe with column names you might be able to easily remove the data you don’t want to appear using something like this: hover_data={'column_name_1': False, 'column_name_2': False}.

Here’s the docs for more info on hover text and formatting.
Hope that helps.

1 Like

Alternatively, you can provide a hover_template

fig.update_traces(
    hovertemplate='<b>%{x}</b><br>NĂşmero de ingressantes=%{y}'
)

Read more on that here: Hover text and formatting in Python

1 Like

Thank you for your answers!

Both of them worked like a charm!

Best regards!

2 Likes