我正在尝试在 Jupyter Notebook 中使用 HyperNetX 绘制超图。具体来说,我在我自己的笔记本中遵循https://pnnl.github.io/HyperNetX/build/overview/index.html#license上的教程 1 。这是我的代码:
import matplotlib.pyplot as plt
import networkx as nx
import hypernetx as hnx
scenes = {
0: ('FN', 'TH'),
1: ('TH', 'JV'),
2: ('BM', 'FN', 'JA'),
3: ('JV', 'JU', 'CH', 'BM'),
4: ('JU', 'CH', 'BR', 'CN', 'CC', 'JV', 'BM'),
5: ('TH', 'GP'),
6: ('GP', 'MP'),
7: ('MA', 'GP')
}
H = hnx.Hypergraph(scenes)
hnx.draw(H)
但是,每次我尝试绘制 Hypergraph 时,都会收到以下错误消息:
IndexError Traceback (most recent call last)
/opt/anaconda3/lib/python3.8/site-packages/networkx/utils/decorators.py in _random_state(func, *args, **kwargs)
395 try:
--> 396 random_state_arg = args[random_state_index]
397 except TypeError as e:
IndexError: tuple index out of range
The above exception was the direct cause of the following exception:
NetworkXError Traceback (most recent call last)
<ipython-input-3-5fa46e21aefe> in <module>
1 # Draw the hypergraph! For more on using all of the parameters
2 # of the draw function see the Visualization tutorial
----> 3 hnx.draw(H)
/opt/anaconda3/lib/python3.8/site-packages/hypernetx/drawing/rubber_band.py in draw(H, pos, with_color, with_node_counts, with_edge_counts, layout, layout_kwargs, ax, node_radius, edges_kwargs, nodes_kwargs, edge_labels, edge_labels_kwargs, node_labels, node_labels_kwargs, with_edge_labels, with_node_labels, label_alpha, return_pos)
428
429 if pos is None:
--> 430 pos = layout_node_link(H, layout=layout, **layout_kwargs)
431
432 r0 = get_default_radius(H, pos)
/opt/anaconda3/lib/python3.8/site-packages/hypernetx/drawing/rubber_band.py in layout_node_link(H, layout, **kwargs)
54 mapping of node and edge positions to R^2
55 """
---> 56 return layout(H.bipartite(), **kwargs)
57
58
/opt/anaconda3/lib/python3.8/site-packages/decorator.py in fun(*args, **kw)
229 if not kwsyntax:
230 args, kw = fix(args, kw, sig)
--> 231 return caller(func, *(extras + args), **kw)
232 fun.__name__ = func.__name__
233 fun.__doc__ = func.__doc__
/opt/anaconda3/lib/python3.8/site-packages/networkx/utils/decorators.py in _random_state(func, *args, **kwargs)
398 raise nx.NetworkXError("random_state_index must be an integer") from e
399 except IndexError as e:
--> 400 raise nx.NetworkXError("random_state_index is incorrect") from e
401
402 # Create a numpy.random.RandomState instance
NetworkXError: random_state_index is incorrect
不知道如何解决这个问题?