✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

How to select y second value when customizing hovertemplate (px.line)

Hi everyone,
I want to customize hovertemplate (px.line) to add a symbol next to one of the value of y. I have 2 y variables in my px.line(), so when I use {y} in my syntax, the symbol will appear next to both y axis/values (Both next to the value of 'Lobbying' and the value of 'Contract (10 millions (C))’.

How can I select only one of the y value so that the symbol can appear only next to the value of 'Contract (10 millions (C))’ ?

My code :

fig = px.line(df, x=‘DATE’, y=[‘Lobbying’, ‘Contract (10 millions (C$))’], color=‘variable’, facet_col=‘INSTITUTION’, facet_col_wrap=4, line_dash =‘variable’, hover_name=‘INSTITUTION’, line_shape=“linear”, render_mode=“svg”)
fig.update_layout(xaxis_range=[‘2009-06-30’,‘2019-12-31’], title_text=“Lobbying and Public Contracts”, hovermode=“x unified”, hoverlabel=dict(
bgcolor=“white”,
font_size=10,
font_family=“Rockwell”))
fig.update_yaxes(matches=None, title ="")
fig.update_traces(mode=“markers+lines”, hovertemplate=’$%{y}’, hoverinfo=‘x + y’)
plot(fig)

Thanks a lot

Hey, @Mboucher have you solved it, bro?

I’m with the same problem at this moment

Unfortunately no! I kinda found a way to avoid the problem by changing the name of my variables. Let me know if you found a way to select the second y value with hovertemplate. And thank you for your message Mr. Ferreira. Long live Plotly.