Plotly Backend Hover Data

Hey guys,

I was wondering if there is a way to customize the hover data on the Plotly backend. I want to add more information to data box when hovering over a point.

Thanks

I have the same question. If there is a way to pass parameters to plotly layout so that I can get the equivalent of the following plotly command using holoviews as the front end.

fig.update_layout(hoverlabel = dict(namelength = -1)) # show full string in hover label plotly

Seems like it should be possible with hooks and the following works using hooks so please share any changes you do to code to add more info when hovering over a point

_g_plot=[]
_g_element=[]
_g_counter=0

def hv_hook_plotly_legend(plot,element):
    ''' 
        Fixes single trace enable/disable issue in plotly hvplot by assigning unique group to legendgroup  and hoverlabel length to max  
        plot and element . called once for each trace so this is called multiple times
        usage: fig.opts(hooks=[hv_hook_plotly_legend]) 
        where fig is hvplot object. ex: fig=df.hvplot()
        This function will be called for each trace so redundant after first trace but havent figure out how to process for each element instead of plot every time
    '''
    global _g_counter,_g_plot,_g_element # globals to see what is getting passed via hook function. useful for adding features
    _g_plot=plot
    _g_element=element
    _g_counter +=1
    # print('hook called',type(plot),type (element))
    for index,trace in enumerate (plot.state['data']):
       # g_plot.state['data'] [0]['legendgroup'] is the format
        # sometimes only single trace is passed every call of hook so use g_counter to allow unique legendgruop entries
        try: trace['legendgroup']=trace['legendgroup']+'_'+str(_g_counter+index) # add index to make legendgroup text unique for each trace allowing en/disable
        except: pass
    #fig.update_layout(hoverlabel = dict(namelength = -1)) # show full string in hover label plotly
    _g_plot.handles['fig']['layout']['hoverlabel'] =dict(namelength = -1) # show full string in hover label plotly
1 Like