Custom Hovermode

Hi there,

I am trying to display the percentage and also the count on this histogram hover label using this hovertemplate documentation, doesn’t seem to be working?

example label:

Percentage: 84%
Count: 5344


region_mirco_census_filtered_test = region_mirco_census[region_mirco_census['UK region'] == 'South East']

Region = go.Histogram(
    x=region_mirco_census_filtered_test['Characteristic - Ethnicity'], histnorm='percent',
    opacity=0.4, name="Region", hovertemplate = region_mirco_census['Characteristic - Ethnicity'].value_counts()
)
UK_average = go.Histogram(
    x=region_mirco_census['Characteristic - Ethnicity'], histnorm='percent', marker=dict(color='rgba(0,0,0,0)', line=dict(width=2, color='red')),
    opacity=0.6, name="UK average", hovertemplate = region_mirco_census['Characteristic - Ethnicity'].value_counts()
)

data = [Region, UK_average]
layout = go.Layout(barmode='overlay')
fig1 = go.Figure(data=data, layout=layout)

fig1.show()


Hi,

Hovertemplate should be a template string with some special syntax, which allows you to combine x and y coordinates easily with the text. That said, I don’t think the pre-defined variables would contain both the percentage and count in your histogram, therefore you need to specify the two columns as customdata.

Here’s a recent thread about this very same topic: Histogram plot hover data not showing all columns - #2 by jlfsjunior

Hope this helps!

3 Likes