Holoviews-Matplotlib#

This notebook discusses how to use the HivePlot class with the holoviews-matplotlib visualization back end.

Note: the holoviews-matplotlib viz back end requires that Hiveplotlib be installed with extra packages, which can be done by running:

pip install hiveplotlib[holoviews]
[1]:
from hiveplotlib.datasets import example_hive_plot

Change Plotting Kwargs For Nodes, Edges, and Axes#

By default, Hiveplotlib viz keeps all colors black, with standardized sizes that should cover most users’ needs:

[2]:
hp = example_hive_plot(backend="holoviews-matplotlib")

fig = hp.plot()
fig.opts(title="Base Holoviews-Matplotlib Hive Plot Viz")
fig
[2]:

All of these defaults, however, can be modified. Below, we modify every color and size to serve as a reference for how to change these defaults with the holoviews-matplotlib back end:

[3]:
fig = hp.plot(
    # node kwarg changes
    node_kwargs={
        "s": 150,
        "color": "None",  # empty node fill color
        "edgecolor": "blue",
        "linewidth": 2,
        "alpha": 0.4,
    },
    # axes label kwarg changes
    axes_labels_fontsize=32,
    text_kwargs={
        "color": "purple",
        "weight": "bold",
    },
    # axes kwarg changes
    axes_kwargs={
        "linewidth": 10,
        "color": "yellow",
        "alpha": 0.9,
    },
    # edge kwarg changes
    color="red",
    linewidth=3,
    alpha=0.1,
)
fig
[3]:

Plotting Node Metadata#

Users may want to visualize nodes with respect to node metadata. For more on visualizing node metadata, see the Visualizing Node Metadata page.

Below, we demonstrate modifying nodes according to metadata for both size and color.

[4]:
hp = example_hive_plot(
    repeat_axes=True,
    backend="holoviews-matplotlib",
)

# scale the low variable to make more useful sizes in viz
hp.nodes.data["size"] = hp.nodes.data["low"].to_numpy() * 10

# propagate extra node data changes through to data on axes
hp.update_partition_data()

node_kwargs = {
    "color": "low",  # reference to "low" var in node data
    "s": "size",  # reference to "size" var in node data
    "edgecolor": "black",
    "colorbar": True,
    "clim": (0, 10),  # fixed color range consistent between each axis
    "cmap": "magma",
    "clabel": "Node Variable 'low'",
    "cbar_padding": 0.1,
}

hp.update_node_viz_kwargs(**node_kwargs)

fig = hp.plot()

fig
[4]:

Plotting Edge Metadata#

Users may want to visualize edges with respect to edge metadata. For more on visualizing edge metadata, see the Visualizing Edge Metadata page.

Below, we demonstrate modifying edges according to metadata for both line width and color.

[5]:
hp = example_hive_plot(
    repeat_axes=True,
    backend="holoviews-matplotlib",
)

# scale the low variable to make more useful line widths in viz
hp.edges.data["linewidth"] = hp.edges.data["low"] / 3

edge_kwargs = {
    "color": "low",  # reference to "low" var in edge data
    "linewidth": "linewidth",  # reference to "linewidth" variable in edge data
    "colorbar": True,
    "clim": (0, 10),  # fixed color range consistent between each axis
    "cmap": "cividis",
    "clabel": "Edge Variable 'low'",
}

hp.update_edge_plotting_keyword_arguments(**edge_kwargs)

fig = hp.plot()

fig
[5]: