Hover Information#
This notebook covers how to include / modify hover information.
[1]:
import numpy as np
from bokeh.io import output_notebook
from bokeh.plotting import show
from hiveplotlib.datasets import example_hive_plot
output_notebook()
We will base this discussion on the following toy hive plot:
[2]:
hp = example_hive_plot(backend="bokeh")
We will focus specifically on the bokeh viz back end here, but hover information is also supported with the plotly and holoviews-bokeh back ends.
For more on the nuances when using each of these interactive viz back ends, see the pages for plotting with bokeh, plotly, and holoviews-bokeh.
The following discussion applies to all of the viz back ends, but since we are using the bokeh back end, this notebook will only run if Hiveplotlib is installed with the bokeh dependencies via:
pip install hiveplotlib[bokeh]
Default Hover Behavior#
By default, when using one of the interactive back ends for visualization (bokeh, holoviews-bokeh, or plotly), the resulting visualization will incorporate all possible hover information.
Specifically, the interactive viz back ends by default provide hover info for nodes, edges, and axes.
[3]:
fig = hp.plot()
show(fig)
Include Additional Hover Information#
hiveplotlib supports including additional hover info for nodes / edges / axes.
Add More Hover Info to Nodes#
We can add more node metadata directly to the HivePlot.nodes.data DataFrame attribute.
[4]:
hp.nodes.data.head()
[4]:
| unique_id | low | med | high | partition_0 | |
|---|---|---|---|---|---|
| 0 | 0 | 6.363247 | 14.795079 | 23.193620 | B |
| 1 | 1 | 2.695169 | 12.321405 | 21.873202 | A |
| 2 | 2 | 0.409326 | 18.010787 | 26.718541 | A |
| 3 | 3 | 0.165111 | 19.226066 | 21.949123 | A |
| 4 | 4 | 8.124570 | 12.658641 | 25.771102 | C |
[5]:
# make unique values for each node in a new node data column
rng = np.random.default_rng(0)
hp.nodes.data["Special Node Data"] = rng.uniform(size=len(hp.nodes.data))
[6]:
hp.nodes.data.head()
[6]:
| unique_id | low | med | high | partition_0 | Special Node Data | |
|---|---|---|---|---|---|---|
| 0 | 0 | 6.363247 | 14.795079 | 23.193620 | B | 0.636962 |
| 1 | 1 | 2.695169 | 12.321405 | 21.873202 | A | 0.269787 |
| 2 | 2 | 0.409326 | 18.010787 | 26.718541 | A | 0.040974 |
| 3 | 3 | 0.165111 | 19.226066 | 21.949123 | A | 0.016528 |
| 4 | 4 | 8.124570 | 12.658641 | 25.771102 | C | 0.813270 |
Note, we will need to run the HivePlot.update_partition_data() call to propagate the new node metadata to the resulting visualization:
[7]:
# propagate extra node data changes through to data on axes
hp.update_partition_data()
[8]:
fig = hp.plot()
show(fig)
Add More Hover Info to Edges#
We can add more edge metadata directly to the HivePlot.Edges.data DataFrame attribute.
[9]:
hp.edges.data.head()
[9]:
| from | to | low | med | high | |
|---|---|---|---|---|---|
| 0 | 85 | 63 | 6.567506 | 15.711859 | 24.629851 |
| 1 | 51 | 26 | 6.176714 | 16.259557 | 24.106476 |
| 2 | 30 | 4 | 7.501076 | 14.257005 | 26.436396 |
| 3 | 7 | 1 | 4.991420 | 15.811134 | 21.297566 |
| 4 | 17 | 81 | 5.189225 | 11.564580 | 26.122606 |
[10]:
# make unique values for each edge in a new edge data column
rng = np.random.default_rng(0)
hp.edges.data["Special Edge Data"] = rng.uniform(size=len(hp.edges.data))
[11]:
hp.edges.data.head()
[11]:
| from | to | low | med | high | Special Edge Data | |
|---|---|---|---|---|---|---|
| 0 | 85 | 63 | 6.567506 | 15.711859 | 24.629851 | 0.636962 |
| 1 | 51 | 26 | 6.176714 | 16.259557 | 24.106476 | 0.269787 |
| 2 | 30 | 4 | 7.501076 | 14.257005 | 26.436396 | 0.040974 |
| 3 | 7 | 1 | 4.991420 | 15.811134 | 21.297566 | 0.016528 |
| 4 | 17 | 81 | 5.189225 | 11.564580 | 26.122606 | 0.813270 |
We will now see the additional edge metadata on each edge’s hover info:
[12]:
fig = hp.plot()
show(fig)
Add More Hover Info to Axes#
To add additional metadata to an axis, we can call the hiveplotlib.Axis.add_metadata() method.
[13]:
# make unique values for each axis in a new axis metadata value
axis_metadata_values = [i for i, _ in enumerate(hp.axes)]
for i, ax in enumerate(hp.axes):
hp.axes[ax].add_metadata(
{"Special Axis Data": f"{axis_metadata_values[i]}"}
)
We will now see the additional axis metadata on each axis’ hover info:
[14]:
fig = hp.plot()
show(fig)
Showing Subset of Hover Information#
Setting hover information is controlled with the hover parameter in the HivePlot.plot() call.
By default, this is set to hover=True, which is equivalent to setting hover=["nodes", "edges", "axes"].
Currently, hiveplotlib supports showing or excluding hover information for any combination of:
Node hover info
Edge hover info
Axis hover info
In other words, users can either show all node hover info, or no node hover info. The same goes for edge hover info and axis hover info.
For example, to only show node hover info, we can set hover="nodes" (or hover=["nodes"]):
[15]:
fig = hp.plot(
hover="nodes", # show node hover info only
)
show(fig)
Or we could only show edge and axis info with hover=["edges", "axes"]:
[16]:
fig = hp.plot(
hover=["edges", "axes"], # show edge and axis hover info only
)
show(fig)
Turn Off All Hover Information#
If we don’t want any hover info, we can always turn it off by setting hover=False.
[17]:
fig = hp.plot(
hover=False, # turn off hover info
)
show(fig)