Spaces:
Sleeping
Sleeping
File size: 482 Bytes
db9ca60 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import hypernetx as hnx
import matplotlib.pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from io import BytesIO
def draw_hypergraph(hyperedges):
# 构建超图
H = hnx.Hypergraph(hyperedges)
# 绘制超图
fig, ax = plt.subplots(figsize=(12, 8))
hnx.draw(H, ax=ax)
# 将超图保存为图像
canvas = FigureCanvas(fig)
buffer = BytesIO()
canvas.print_png(buffer)
buffer.seek(0)
return buffer |