I created a Chord diagram and by default this hover text appeared:
I want to skip the index and replace “name” by “Region”. I tried to configure a custom Hovertool but it doesn’t recognize the name of the regions, but the default hover does. Any idea? This is the code:
Creo dataframe de links
df_links = pd.DataFrame(columns = [‘source’, ‘target’, ‘value’])
df_links[‘source’] = df[‘Origin_Nuts2_Name’].values.tolist()
df_links[‘target’] = df[‘Destination_Nuts2_Name’].values.tolist()
df_links[‘value’] = df[‘MEAN_SUM_Flow_Euros_NUTS3’].values.tolist()
Saco lista de regiones
unique_names = set(df[‘Origin_Nuts2_Name’].unique().tolist() + df[‘Destination_Nuts2_Name’].unique().tolist())
Creo dataframe de nodos
df_nodes = pd.DataFrame(columns=[‘name’])
df_nodes[‘name’] = list(unique_names)
Mapping to numerical value for the source and target node
mapper = {key: i for i, key in enumerate(list(unique_names))}
df_links[‘source’] = df_links[‘source’].map(mapper)
df_links[‘target’] = df_links[‘target’].map(mapper)
links = df_links
nodes = hv.Dataset(df_nodes, ‘index’)
from bokeh.models import HoverTool
hover = HoverTool(tooltips=[
(“Region”, “$name”)
])
chord = hv.Chord((links, nodes)).select(value=(5, None)).opts(opts.Chord(height=400,
width=400,
node_size=16,
title=“Flows of goods from France and Portugal to Spain. Importations”,
cmap=‘Category20’,
edge_cmap=‘Category20’,
edge_alpha=0.8,
tools=[hover],
edge_color=dim(‘source’).astype(str),
labels=‘name’,
node_color=dim(‘index’).astype(str)))