I have this dataframe
df = pd.DataFrame({'time':[1,2,3,1,2,3],
'department':['A','A','A','B','B','B'],
'revenue':[10,11,12,13,14,15]})
I plotted it using
import plotly.express as px
fig = px.line(df,x=df.time,y=df.revenue,color=df.department)
fig.update_traces(mode='lines + markers',
hovertemplate = 'Revenue: %{y:.d} <br>')
fig.show()
I was able to have the 'revenue' showing up on the hover-template box but I also want to have the 'department' showing up too. However, I'm not really sure how to do this. Could somebody help me out please
You can add hover_name="department" as shown:
fig = px.line(df,x="time",y="revenue",color="department",hover_name="department")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.