Function Repository Resource:

WolframModelPlot

Source Notebook

Generate a visual display of a hypergraph

Contributed by: Wolfram Research

ResourceFunction["WolframModelPlot"][g]

generates a plot of the hypergraph g.

ResourceFunction["WolframModelPlot"][{g1,g2,}]

generates a list of plots of the hypergraphs gi.

ResourceFunction["WolframModelPlot"][data,"type"]

generates plots assuming hypergraphs of the specified type.

Details and Options

ResourceFunction["WolframModelPlot"] attempts to place vertices to give a well-laid-out version of the hypergraph.
In ResourceFunction["WolframModelPlot"][g], g should be a list of hyperedges: {{n11,n12,},{n21,},}.
Unary edges are supported and displayed as circles around the vertices.
In ResourceFunction["WolframModelPlot"][data,"type"], possible types of hypergraphs to assume include:
"Ordered"every hyperedge is interpreted as a sequence of directed edges of adjacent vertices
"Cyclic"the same as "Ordered", with an addition of a directed edge from the last vertex to the first
WolframModelPlot has the same options as Graphics, with following additions:
"ArrowheadLength"Automaticthe length of arrowheads
"EdgePolygonStyle"Automaticstyle for hyperedge polygons
"HyperedgeRendering""Polygons"how to render hyperedges in the hypergraph
"MaxImageSize"Automaticupper limit for the image size
EdgeStyleAutomaticstyle for edges
GraphHighlight{}vertices and hyperedges to highlight
GraphHighlightStyleRedhighlight color
PlotStyleAutomaticoverall style
VertexCoordinateRules{}coordinates specified for particular vertices
VertexLabelsNonelabels for vertices
VertexSize0.06the size of vertices
VertexStyleAutomaticstyle for vertices
Possible settings for "HyperedgeRendering" include:
"Subgraphs"render hyperedges as ordinary graphs
"Polygons"render hyperedges as polygons
Install the SetReplace paclet to get better performance and bleeding-edge functionality.
See the SetReplace README for a more detailed documentation.

Examples

Basic Examples (3) 

Plot a hypergraph:

In[1]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}}]
Out[1]=

Plot multiple hypergraphs:

In[2]:=
ResourceFunction[
 "WolframModelPlot"][{{{1, 2, 3}}, {{1, 2, 3}, {3, 4, 5}}, {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}}}]
Out[2]=

Plot a cyclic hypergraph:

In[3]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}}, "Cyclic"]
Out[3]=

Scope (4) 

Unary edges are shown as circles around the vertices:

In[4]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4}, {4, 3}, {4, 5, 6}, {1}, {6}, {6}}]
Out[4]=

Self-loops are shown as convex polygons around the appropriate number of circular arrows:

In[5]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 1, 1}, {1, 2, 3}, {3, 4, 4}}]
Out[5]=

Note the difference between a hyper-self-loop and two binary edges pointing in opposite directions:

In[6]:=
ResourceFunction["WolframModelPlot"][{{1, 2, 1}, {2, 3}, {3, 2}}]
Out[6]=

Multiedges are shown as multiple arrows and polygons:

In[7]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {3, 4, 5}, {1, 6, 6}, {1, 6, 6}}]
Out[7]=

Options (17) 

GraphHighlight (1) 

Highlight some vertices and edges:

In[8]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, GraphHighlight -> {{1, 2, 3}, 4, {9}}]
Out[8]=

GraphHighlightStyle (1) 

Change the color of the highlight:

In[9]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, GraphHighlight -> {{1, 2, 3}, 4, {9}}, GraphHighlightStyle -> Darker@Green]
Out[9]=

HyperedgeRendering (1) 

Unroll each hypergraph to a sequence of binary edges:

In[10]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, "HyperedgeRendering" -> "Subgraphs"]
Out[10]=

VertexCoordinateRules (1) 

Specify custom coordinates for the vertices:

In[11]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {2, 4, 5}, {2, 6, 7, 8}, {8, 9, 1}}, VertexCoordinateRules -> {1 -> {0, 0}, 2 -> {1, 0}, 3 -> {0, 1}}]
Out[11]=

VertexLabels (1) 

Display the labels for vertices:

In[12]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {2, 4, 5}, {2, 6, 7, 8}, {8, 9, 1}}, VertexLabels -> Automatic]
Out[12]=

VertexSize (1) 

Make vertices appear larger:

In[13]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3, 4}, {1, 5, 6}, {2, 7, 8}, {4, 6, 9}}, VertexSize -> 0.1]
Out[13]=

ArrowheadLength (1) 

Make arrowheads appear larger:

In[14]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3, 4}, {1, 5, 6}, {2, 7, 8}, {4, 6, 9}}, "ArrowheadLength" -> 0.3]
Out[14]=

MaxImageSize (1) 

Reduce the maximum image size, but keep small hypergraphs small:

In[15]:=
ResourceFunction["WolframModelPlot"][{{{1}}, {{1, 1}}, {{1, 2, 3}}}, "MaxImageSize" -> 100]
Out[15]=

PlotStyle (1) 

Specify an overall style:

In[16]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, PlotStyle -> Orange]
Out[16]=

VertexStyle (3) 

Specify a style for vertices:

In[17]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, VertexStyle -> Orange]
Out[17]=

Styles for each vertex can be given as a List:

In[18]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, VertexStyle -> ColorData[98] /@ Range[9]]
Out[18]=

Styles for different vertex patterns can be given as an Association:

In[19]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, VertexStyle -> <|_?OddQ -> Red|>]
Out[19]=

EdgeStyle (3) 

Specify a style for edges:

In[20]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, EdgeStyle -> Orange]
Out[20]=

Styles for each edge can be given as a List:

In[21]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, EdgeStyle -> ColorData[98] /@ Range[6]]
Out[21]=

Styles for different edge patterns can be given as an Association:

In[22]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, EdgeStyle -> <|{_} -> Darker@Blue, {_, _} -> Darker@Green, {_, _, _} -> Darker@Red, {_, _, _, _} -> Darker@Yellow|>]
Out[22]=

EdgePolygonStyle (2) 

Specify a style for edge polygons:

In[23]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, "EdgePolygonStyle" -> LightOrange]
Out[23]=

This can be specified independently from the style for edge lines:

In[24]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4, 9}, {9}}, EdgeStyle -> Red, "EdgePolygonStyle" -> LightOrange]
Out[24]=

Properties and Relations (2) 

WolframModelPlot is used in various properties of WolframModel:

In[25]:=
ResourceFunction[
  "WolframModel"][{{x, y}, {x, z}} -> {{x, z}, {x, w}, {y, w}, {z, w}}, {{0, 0}, {0, 0}}, 10, "FinalStatePlot"]
Out[25]=

It is also used in RulePlot:

In[26]:=
RulePlot[ResourceFunction[
   "WolframModel"][{{1, 2}, {1, 2}} -> {{3, 2}, {3, 2}, {2, 1}, {1, 3}}]]
Out[26]=

Possible Issues (2) 

It may be hard to see the boundaries between hyperedges:

In[27]:=
ResourceFunction["WolframModelPlot"][{{3, 1, 2}, {2, 4, 3}}]
Out[27]=

Using different colors for each edge might help:

In[28]:=
ResourceFunction["WolframModelPlot"][{{3, 1, 2}, {2, 4, 3}}, EdgeStyle -> <|_ :> RandomColor[]|>]
Out[28]=

Manually specifying coordinates might break the scaling, so vertices and arrowheads may appear too large relative to the distance between vertices:

In[29]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {2, 4, 5}, {2, 6, 7, 8}, {8, 9, 1}}, VertexCoordinateRules -> {1 -> {0, 0}, 2 -> {1, 0}}]
Out[29]=

Manually reduce the vertex/arrowhead sizes to get a better-looking image:

In[30]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {2, 4, 5}, {2, 6, 7, 8}, {8, 9, 1}}, VertexCoordinateRules -> {1 -> {0, 0}, 2 -> {1, 0}}, VertexSize -> 0.03, "ArrowheadLength" -> 0.06]
Out[30]=

Neat Examples (3) 

Make polygon art by getting rid of the vertices and arrowheads:

In[31]:=
ResourceFunction[
 "WolframModelPlot"][{{1, 2, 3}, {3, 4, 5}, {5, 6, 7}, {7, 8, 9}, {9, 10, 1}}, "Cyclic", "ArrowheadLength" -> 0, VertexSize -> 0, VertexStyle -> Transparent]
Out[31]=

Make an unordered hypergraph plot by specifying a custom edge style:

In[32]:=
ResourceFunction[
 "WolframModelPlot"][{{1}, {1, 2}, {2, 3}, {3, 4, 5}, {5, 6, 7, 1}}, "ArrowheadLength" -> 0, EdgeStyle -> <|{_, _, _ ..} -> Transparent|>,
  "EdgePolygonStyle" -> <|{_, _, _ ..} -> Directive[Hue[0.63, 0.66, 0.81], Opacity[0.1], EdgeForm[Directive[Hue[0.63, 0.7, 0.5], Opacity[0.7]]]]|>]
Out[32]=

Display binary and ternary edges in different colors:

In[33]:=
ResourceFunction["WolframModelPlot"][
 ResourceFunction[
   "WolframModel"][{{1, 2, 3}, {4, 5, 6}, {2, 5}, {5, 2}} -> {{7, 1, 8}, {9, 3, 10}, {11, 4, 12}, {13, 6, 14}, {7, 13}, {13, 7}, {8, 10}, {10, 8}, {9, 11}, {11, 9}, {12, 14}, {14, 12}}, {{1, 2, 3}, {4, 5, 6}, {1, 4}, {4, 1}, {2, 5}, {5, 2}, {3, 6}, {6, 3}}, 6,
   "FinalState"], EdgeStyle -> <|{_, _} -> Darker@Green, {_, _, _} -> Darker@Red|>]
Out[33]=

Version History

  • 6.0.0 – 23 June 2020
  • 5.0.0 – 14 April 2020
  • 4.0.0 – 07 April 2020
  • 3.0.0 – 10 March 2020
  • 2.0.0 – 26 February 2020
  • 1.0.0 – 26 February 2020

Related Resources

License Information