0
# Visualization and Drawing
1
2
Visualization capabilities for hypergraph display including rubber band layouts, incidence upset plots, and bipartite representations. These functions provide multiple ways to visualize hypergraph structure and relationships.
3
4
## Capabilities
5
6
### Primary Drawing Function
7
8
Main hypergraph visualization using rubber band layout algorithm that positions nodes and draws hyperedges as enclosing shapes.
9
10
```python { .api }
11
def draw(
12
H: "Hypergraph",
13
**kwargs
14
) -> Any:
15
"""
16
Draw hypergraph using rubber band layout.
17
18
Parameters:
19
- H: Input hypergraph
20
- **kwargs: Drawing parameters including:
21
- pos: Node positions (dict)
22
- node_color: Node colors
23
- node_size: Node sizes
24
- edge_color: Edge colors
25
- with_node_labels: Show node labels
26
- with_edge_labels: Show edge labels
27
- ax: Matplotlib axes object
28
- layout: Layout algorithm
29
- figsize: Figure size tuple
30
31
Returns:
32
Matplotlib figure or axes object
33
"""
34
```
35
36
Usage example:
37
38
```python
39
import hypernetx as hnx
40
import matplotlib.pyplot as plt
41
42
# Create a simple hypergraph
43
H = hnx.Hypergraph({'E1': ['A', 'B', 'C'], 'E2': ['B', 'C', 'D']})
44
45
# Basic drawing
46
hnx.draw(H)
47
plt.show()
48
49
# Customized drawing
50
hnx.draw(H,
51
node_color='lightblue',
52
node_size=300,
53
edge_color=['red', 'blue'],
54
with_node_labels=True,
55
with_edge_labels=True,
56
figsize=(10, 8))
57
plt.show()
58
```
59
60
### Incidence Upset Plot
61
62
Specialized visualization showing hypergraph structure as an upset plot, which effectively displays set intersections and memberships.
63
64
```python { .api }
65
def draw_incidence_upset(
66
H: "Hypergraph",
67
**kwargs
68
) -> Any:
69
"""
70
Draw hypergraph as incidence upset plot.
71
72
Parameters:
73
- H: Input hypergraph
74
- **kwargs: Upset plot parameters including:
75
- sort_by: Sorting criteria ('cardinality', 'degree')
76
- subset_size: Type of subset size display
77
- show_counts: Show intersection counts
78
- figsize: Figure size tuple
79
- min_subset_size: Minimum subset size to display
80
- max_subset_size: Maximum subset size to display
81
82
Returns:
83
Matplotlib figure showing upset plot
84
"""
85
```
86
87
Usage example:
88
89
```python
90
import hypernetx as hnx
91
92
# Create hypergraph with multiple overlapping edges
93
H = hnx.Hypergraph({
94
'E1': ['A', 'B', 'C'],
95
'E2': ['B', 'C', 'D', 'E'],
96
'E3': ['A', 'D'],
97
'E4': ['C', 'E', 'F']
98
})
99
100
# Draw upset plot
101
hnx.draw_incidence_upset(H,
102
sort_by='cardinality',
103
show_counts=True,
104
figsize=(12, 8))
105
plt.show()
106
```
107
108
### Bipartite Euler Diagram
109
110
Visualization of hypergraph as bipartite graph using Euler diagram representation, showing nodes and edges as separate vertex sets.
111
112
```python { .api }
113
def draw_bipartite_using_euler(
114
H: "Hypergraph",
115
**kwargs
116
) -> Any:
117
"""
118
Draw hypergraph as bipartite Euler diagram.
119
120
Parameters:
121
- H: Input hypergraph
122
- **kwargs: Bipartite drawing parameters including:
123
- node_color: Colors for node vertices
124
- edge_color: Colors for edge vertices
125
- node_shape: Shape for node vertices
126
- edge_shape: Shape for edge vertices
127
- pos: Position layout
128
- with_labels: Show vertex labels
129
- figsize: Figure size tuple
130
131
Returns:
132
Matplotlib figure showing bipartite representation
133
"""
134
```
135
136
Usage example:
137
138
```python
139
import hypernetx as hnx
140
import matplotlib.pyplot as plt
141
142
# Create hypergraph
143
H = hnx.Hypergraph({
144
'E1': ['A', 'B', 'C'],
145
'E2': ['B', 'C', 'D'],
146
'E3': ['A', 'D', 'E']
147
})
148
149
# Draw bipartite representation
150
hnx.draw_bipartite_using_euler(H,
151
node_color='lightblue',
152
edge_color='lightcoral',
153
node_shape='o',
154
edge_shape='s',
155
with_labels=True,
156
figsize=(10, 6))
157
plt.show()
158
```