Hovertemplate: custom data not showing

Hi all,
I have the following dataframe

publicationDate signingDate  nif_contratante                                        contratante  ...                                         contratada         contract_date  price reported
0      24-02-2020  04-02-2020      600081290.0             Agrupamento de Escolas de Porto de Mós  ...               The Irish College of English Limited  2020-02-04T00:00:00Z   7914      NaN
1      26-02-2020  13-02-2020      600000052.0        Instituto de Oftalmologia do Dr. Gama Pinto  ...                 Instituto de Soldadura e Qualidade  2020-02-13T00:00:00Z     90      NaN
2      27-02-2020  27-02-2020      501442600.0  Instituto do Emprego e da Formação Profissiona...  ...  ASSOCIAÇÃO HUMANITÁRIA DOS BOMBEIROS VOLUNTÁRI...  2020-02-27T00:00:00Z    500      NaN

And the following code:

data = pd.read_csv('basecovid19_ad.csv')

chart3=px.bar(x=data['contract_date'], y=data['price'], color= data['price'],
			range_x=['2020-03-01','2021-05-01'],
			labels=dict(x="Data de Publicação", y="Valor (M€)", color="Valor em Euros",
			custom_data=[data['contratante'], data['contratada']])
			)
			


chart3.update_xaxes(title_font=dict(size=18, family='Lato', color='#1a1a1e'))

chart3.update_yaxes(title_font=dict(size=18, family='Lato', color='#1a1a1e'))

chart3.update_traces(
	hovertemplate="<br>".join([
        "DATA: %{x}",
        "VALOR: %{y}",
        "Entidade: {contratante}",
        "Empresa: {contratada}",
     ])
    )
chart3.show()

This is the result:
Screenshot 2021-05-06 at 14.42.43

For some reason custom_data is not pulling the values from the data dataframe, or my script has some error that I’m not able to sort out.
Any help would be appreciated.
Thank you in advance!

Hi

From the documentation(plotly.express.bar — 4.14.3 documentation):

  • custom_data ( list of str or int , or Series or array-like ) – Either names of columns in data_frame , or pandas Series, or array_like objects Values from these columns are extra data, to be used in widgets or Dash callbacks for example. This data is not user-visible but is included in events emitted by the figure (lasso selection etc.)

Custom data cannot be seen by the user.

Hence it is advisable to use hover_data with the names of the column in the dataframe to contain the names that you want in the label. It would also use the same colon like structure that you would like to reproduce.

Hope this helps!

1 Like

Thank you @sparkmaddy, that actually helps a lot. I will post the code with the solution based on that.