How to visualize a simple hypergraph¶

Install the SimpleHypergraphs package.

In [ ]:
#] add SimpleHypergraphs

Include the library package with using.

In [10]:
using SimpleHypergraphs

Let's initialize a simple hypergraph, containing Float weights and Int metadata for both vertices and hyperedges.

In [11]:
h = Hypergraph{Float64, Int, Int}(7,4)
h[1:3,1] .= 1.5
h[6:7,1] .= 1
h[3,4] = 2.5
h[2,3] = 3.5
h[4,3:4] .= 4.5
h[5,4] = 5.5
h[5,2] = 6.5

h
Out[11]:
7×4 Hypergraph{Float64, Int64, Int64, Dict{Int64, Float64}}:
 1.5        nothing   nothing   nothing
 1.5        nothing  3.5        nothing
 1.5        nothing   nothing  2.5
  nothing   nothing  4.5       4.5
  nothing  6.5        nothing  5.5
 1.0        nothing   nothing   nothing
 1.0        nothing   nothing   nothing

Setting vertex and hyperedge metadata, respectively.

In [12]:
for v=1:nhv(h)
    set_vertex_meta!(h, v, v)
end
In [13]:
for he=1:nhe(h)
    set_hyperedge_meta!(h, he, he)
end

Basic visualization parameters¶

To visualize a given hypergraph h, the user needs to specify two mandatory parameters:

  1. the hypergraph h to draw
  2. which method should be used to visualize h
    • GraphBased represents each hyperedge he with a fake vertex fv to which each vertex v ∈ he is connected.
    • HyperNetX renders an Euler diagram of the hypergraph where vertices are black dots and hyper edges are convex shapes containing the vertices belonging to the edge set.

A GraphBased visualization¶

In [14]:
SimpleHypergraphs.draw(h, GraphBased)
Out[14]:

Vertices options¶

  • If with_node_labels=true, but node_labels is not specified, vertex ids will be used as their label.
In [15]:
SimpleHypergraphs.draw(
    h, 
    GraphBased; 
    width=500, 
    height=500,
    radius=10, #same radius for each node
    node_color = "yellow", #same color for each node
    node_stroke="orange", #same stroke for each node
    stroke_width=2, #same stroke-width value for each node
    node_opacity=0.5, #same opacity for each node
    with_node_labels=true, #wheter displaying or not node labels
    with_node_metadata_hover=true,
)
Out[15]:
  • Different radii, colors, strokes, stroke-widths, opacities and labels can be specified for each node. If one of these parameters is specified, the corresponding default value for each vertex will be ignored.
In [16]:
SimpleHypergraphs.draw(
    h, 
    GraphBased; 
    width=500, 
    height=500,
    radius=10, #same radius for each node
    node_color = "yellow", #same color for each node
    node_colors = ["yellow", "yellow", "yellow", "blue", "red", "red", "blue"],
    node_stroke = "orange", #same stroke for each node
    node_strokes =  ["orange", "orange", "orange", "orange", "black", "black", "black"],
    stroke_width=2, #same stroke-width value for each node
    node_opacity=0.5, #same opacity for each node
    with_node_labels=true, #whether displaying or not node labels
    node_labels=["A","B","C","D","E","F","G"],
    with_node_metadata_hover=true,
)
Out[16]:
  • If with_node_weight=true, each vertex weight within the hyperedges it belongs to will be displayed.
In [17]:
SimpleHypergraphs.draw(
    h, 
    GraphBased; 
    width=500, 
    height=500,
    radius=10, #same radius for each node
    node_color = "yellow", #same color for each node
    node_stroke="orange", #same stroke for each node
    stroke_width=2, #same stroke-width value for each node
    node_opacity=0.5, #same opacity for each node
    with_node_labels=true, #whether displaying or not node labels
    node_labels=["A","B","C","D","E","F","G"],
    with_node_metadata_hover=true,
    with_node_weight=true
)
Out[17]:

Hyperedges options¶

In [18]:
SimpleHypergraphs.draw(
    h, 
    GraphBased; 
    width=500, 
    height=500,
    radius=10, #same radius for each node
    node_color = "yellow", #same color for each node
    node_stroke="orange", #same stroke for each node
    stroke_width=2, #same stroke-width value for each node
    node_opacity=0.5, #same opacity for each node
    with_node_labels=true, #whether displaying or not node labels
    with_node_metadata_hover=true,
    with_node_weight=true, #whether displaying vertices metadata on mouse hover
    he_colors=["green", "blue", "red", "yellow"], #hyperedges colors
    with_he_labels=true, #whether displaying or not hyperedge labels
    he_labels=["a","b","c","d"], #hyperedges labels
    with_he_metadata_hover=true #whether displaying hyperedges metadata on mouse hover
)
Out[18]:

A Euler-based visualization¶

SimpleHypergraphs integates the Python library HyperNetX to let the user visualize a hypergraph h exploiting an Euler-diagram visualization. For more details, please refer to the library HyperNetX.

In [19]:
SimpleHypergraphs.draw(h, HyperNetX; width=5, height=5, no_border=true)
In [ ]: