Edge Type | GraphHighlight and GraphHighlightStyle | "HyperedgeRendering" | VertexCoordinates | VertexLabels | VertexSize and "ArrowheadLength" | "MaxImageSize" | Style Options | Graphics Options
HypergraphPlot
(aka WolframModelPlot
) is a function used to
visualize WolframModel
states. It treats lists of vertices as ordered hypergraphs, and displays each hyperedge as a polygon with arrows showing
the ordering:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}}]
Edges of any arity can be mixed. The binary edges are displayed as non-filled arrows, and the unary edges are shown as circles around the vertices:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4}, {4, 3}, {4, 5, 6}, {1}, {6}, {6}}]
Self-loops are shown as convex polygons around the appropriate number of circular arrows:
In[] := HypergraphPlot[{{1, 1, 1}, {1, 2, 3}, {3, 4, 4}}]
Note the difference between a hyper-self-loop and two binary edges pointing in opposite directions:
In[] := HypergraphPlot[{{1, 2, 1}, {2, 3}, {3, 2}}]
Multiedges are shown in a darker color (because of overlaid partially transparent polygons), or as separate polygons depending on the layout (and are admittedly sometimes hard to understand):
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {3, 4, 5}, {1, 6, 6}, {1, 6, 6}}]
Many WolframModel
properties, such as "FinalStatePlot"
and "EventStatesPlotsList"
,
use HypergraphPlot
to produce output. They accept the same set of options, as enumerated below.
By default, HypergraphPlot
assumes the hypergraph edges are ordered. It is also possible to treat edges as cyclic
instead (i.e., assume RotateLeft
and RotateRight
don't change the edge), in which
case "Cyclic"
should be used as the second argument to HypergraphPlot
:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}}, "Cyclic"]
Vertices and edges can be highlighted with the GraphHighlight
option:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4,
9}, {9}}, GraphHighlight -> {{1, 2, 3}, 4, {9}}]
For a hypergraph with multiedges, only the specified number of edges will be highlighted:
In[] := HypergraphPlot[{{1, 2, 3}, {1, 2, 3}, {3, 4}, {3, 4}, {3,
4}, {4}, {4}}, GraphHighlight -> {{1, 2, 3}, {3, 4}, {3, 4}, {4}}]
The style of the highlight can be specified with GraphHighlightStyle
:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4,
9}, {9}}, GraphHighlight -> {{1, 2, 3}, 4, {9}},
GraphHighlightStyle -> Directive[Darker @ Green, Thick]]
By default, HypergraphPlot
represents each hyperedge as a polygon. It is possible instead to drop the polygons (and
the vertex layout adjustments that come with them), and simply split each hyperedge into a collection of binary edges by
setting "HyperedgeRendering"
to "Subgraphs"
. This loses information ({{1, 2}, {2, 3}}
and {{1, 2, 3}}
would
look the same), but might be useful if one does not care to see the separation between hyperedges:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4,
9}, {9}}, "HyperedgeRendering" -> "Subgraphs",
VertexLabels -> Automatic]
It is possible to manually specify some or all coordinates for the vertices:
In[] := HypergraphPlot[{{1, 2, 3}, {2, 4, 5}, {2, 6, 7, 8}, {8, 9, 1}},
VertexCoordinates -> {1 -> {0, 0}, 2 -> {1, 0}, 3 -> {0, 1}},
Axes -> True]
Unfortunately, due to limitations of GraphEmbedding
,
specifying coordinates of two or more vertices breaks the scaling of distances. As a result, vertices and arrowheads
might appear too small or too large and need to be manually adjusted. This might also
affect RulePlot
in some cases.
In[] := HypergraphPlot[{{1, 2, 3}, {2, 4, 5}, {2, 6, 7, 8}, {8, 9, 1}},
VertexCoordinates -> {1 -> {0, 0}, 2 -> {1, 0}}]
In[] := HypergraphPlot[{{1, 2, 3}, {2, 4, 5}, {2, 6, 7, 8}, {8, 9, 1}},
VertexCoordinates -> {1 -> {0, 0}, 2 -> {1, 0}},
VertexSize -> 0.03, "ArrowheadLength" -> 0.06]
"VertexLabels" -> Automatic
displays labels for vertices, similar
to GraphPlot
:
In[] := HypergraphPlot[{{1, 2, 3}, {2, 4, 5}, {2, 6, 7, 8}, {8, 9, 1}},
VertexLabels -> Automatic]
The size of vertices and the length of arrowheads (in the internal graphics units), can be adjusted
with VertexSize
and "ArrowheadLength"
options respectively:
In[] := HypergraphPlot[{{1, 2, 3, 4}, {1, 5, 6}, {2, 7, 8}, {4, 6, 9}},
VertexSize -> 0.1, "ArrowheadLength" -> 0.3]
Note that unlike GraphPlot
, both vertices and arrowheads
have a fixed size relative to the layout (in fact, the arrowheads are drawn manually as polygons). This fixed size
implies that they scale proportionally when the image is resized, and do not overlay/disappear for tiny/huge graphs or
image sizes.
These options can also be used to get rid of vertices and arrowheads altogether:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7}, {7, 8, 9}, {9, 10,
1}}, "Cyclic", "ArrowheadLength" -> 0, VertexSize -> 0,
VertexStyle -> Transparent]
As a neat example, one can even draw unordered hypergraphs:
In[] := HypergraphPlot[{{1, 2, 2}, {2, 3, 3}, {3, 1, 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]]]]|>]
"MaxImageSize"
allows one to specify the image size while allowing for automatic reduction for very small
hypergraphs. To demonstrate that, consider the difference:
In[] := HypergraphPlot[#, "MaxImageSize" -> 100] & /@ {{{1}}, {{1, 1}}, {{1, 2, 3}}}
In[] := HypergraphPlot[#, ImageSize -> 100] & /@ {{{1}}, {{1, 1}}, {{1, 2, 3}}}
There are four styling options: PlotStyle
, VertexStyle
, EdgeStyle
and "EdgePolygonStyle"
.
PlotStyle
controls the overall style for everything, VertexStyle
and EdgeStyle
inherit from it:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4,
9}, {9}}, PlotStyle -> Directive[Blue, Dotted]]
VertexStyle
works similar to GraphPlot
:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4,
9}, {9}}, PlotStyle -> Directive[Blue, Dotted], VertexStyle -> Red]
EdgeStyle
controls edge lines, and "EdgePolygonStyle"
inherits from it (automatically adding transparency):
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4,
9}, {9}}, PlotStyle -> Directive[Blue, Dotted], VertexStyle -> Red,
EdgeStyle -> Darker @ Green]
Finally, "EdgePolygonStyle"
controls the hyperedge polygons:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4,
9}, {9}}, PlotStyle -> Directive[Blue, Dotted], VertexStyle -> Red,
EdgeStyle -> Darker @ Green,
"EdgePolygonStyle" ->
Directive[Lighter[Green, 0.9], EdgeForm[Dotted]]]
It is possible to specify styles separately for each edge and vertex. Vertex styles are specified in the same order
as Union @* Catenate
evaluated on the list of edges:
In[] := HypergraphPlot[{{1, 2, 3}, {3, 4, 5}, {5, 6, 7, 1}, {7, 8, 2}, {4,
9}, {9}}, EdgeStyle -> ColorData[97] /@ Range[6],
VertexStyle -> ColorData[98] /@ Range[9]]
Alternatively, one can specify different styles for different patterns of elements. In this case, styles are specified
as Association
s with patterns for keys. This can be
used to, for example, differently color edges of different arities:
In[] := HypergraphPlot[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|>]
All Graphics
options are supported as well, such
as Background
, PlotRange
, Axes
, etc.:
In[] := HypergraphPlot[WolframModel[{{1, 2}} -> {{1, 3}, {1, 3}, {3, 2}},
{{1, 2}, {2, 3}, {3, 1}}, 7, "FinalState"], Background -> Black,
PlotStyle -> White, GridLines -> Automatic,
PlotRange -> {{30, 50}, {20, 40}}, Axes -> True]