Having this dataframe:
df_grafico2 = pd.DataFrame(data = {
"Usos" : ['Total','BK','BI','CyL','PyA','BC','VA','Resto','Total','BK','BI','CyL','PyA','BC','VA','Resto'],
"Periodo" : ['Octubre 2021*','Octubre 2021*','Octubre 2021*','Octubre 2021*','Octubre 2021*','Octubre 2021*','Octubre 2021*','Octubre 2021*','Octubre 2022*','Octubre 2022*','Octubre 2022*','Octubre 2022*','Octubre 2022*','Octubre 2022*','Octubre 2022*','Octubre 2022*'],
"Dolares" : [5247,869,2227,393,991,606,104,57,6074,996,2334,601,1231,676,202,33]
})
I've tried this plot:
plot_impo_usos = px.histogram(df_grafico2[df_grafico2.Usos != "Total"], x = "Usos", y = "Dolares",color="Periodo", barmode="group", template="none",
hover_data =["Periodo", "Dolares"],
)
plot_impo_usos.update_yaxes(tickformat = ",",title_text='En millones de USD')
plot_impo_usos.update_layout(separators=",.",font_family='georgia', title_text = "Importación por usos económicos. Octubre de 2022 y octubre de 2021",
legend=dict(
yanchor="top", orientation = "h",
y=1.07,
xanchor="left",
x=0.3))
But the hover changes automatically into "sum of Dolares", and it won't be possible to get the "Dolares" name back, even if I try this:
labels={"Usos":"Uso","sum of Dólares": "Dólares"}
The best outcome would be a hover template with: "Periodo", "Uso" and "Dolares" (with $ before).
I've tried this, but it won't work neither:
plot_impo_usos.update_traces(hovertemplate='Periodo: %{color} <br>Uso: %{x} <br>Dolares: $%{y}')
Help is much appreciated!