I've searched for some time now and I can't seem to find a related question. There are similar questions, but nothing that gets to the heart of what I am trying to do with the code I have.
I am trying to add additional text to the hovertext in plotly. Here is my code so far:
import pandas as pd
import numpy as np
from plotly.offline import *
init_notebook_mode(connected=True)
graph1 = merged.groupby(['study_arm', 'visit_label'])['mjsn'].mean().unstack('study_arm')
graph1.iplot(mode='lines+markers',
symbol=['diamond-open', 'square-open', 'circle-dot', 'hexagon-open'],
size=8, colorscale = 'dark2', yTitle='ytitle', xTitle='xtitle',
title='Title of Graph',
hoverformat = '.2f')
hv = merged.groupby(['study_arm', 'visit_label']).size()
print(hv)
Note: 'merged' is the dataframe and is shown in the sample data below.
The code above gives the following output (note: hovering over the timepoint gives some information for each trace, and I took a picture to show what that looks like).
My question is how can I get the subject count number from the table into the hovertext for each trace at each timepoint (preferably on the second line of the hovertext that looks like 'N=x', where x is the subject number from the table under the graph in the picture).
Here is a sample of the dummy dataset I used to create this graph and table:
subject_number visit_label mjsn study_arm
20001 Day 1 0 B
20001 Month 06 0.4 B
20001 Month 12 0.2 B
20003 Day 1 0 B
20003 Month 06 -0.9 B
20003 Month 12 -0.7 B
20005 Day 1 0 C
20005 Month 06 0.1 C
20005 Month 12 -0.1 C
20007 Day 1 0 D
20007 Month 06 0 D
20007 Month 12 -0.3 D
20008 Day 1 0 C
20008 Month 06 -0.3 C
20008 Month 12 -0.1 C
20010 Day 1 0 A
20010 Month 06 -0.6 A
20010 Month 12 -0.4 A
