如何在 matplotlib 轴上绘制 iGraph 对象

How to plot an iGraph object on matplotlib axes

我有一个 iGraph 对象,我想在 Matplotlib 轴上绘制它,

我的图表代码是

from igraph import Graph, Layout
import igraph as ig
karate = Graph.Famous("Zachary")
layout = karate.layout_kamada_kawai()
visual_style={"bbox": (300, 300), "margin": 15, "layout": layout}

cl = karate.community_fastgreedy()
membership = cl.as_clustering().membership
pal = ig.drawing.colors.ClusterColoringPalette(len(membership))
karate.vs["color"] = pal.get_many(cl.as_clustering().membership)
karate.vs["size"] = 15

iGraph 文档说您可以使用

在 Matplotlib 轴内绘图
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ig.plot(g, target=ax)

来源:https://igraph.org/python/doc/tutorial/visualisation.html

然而,当我 运行,

fig, ax = plt.subplots()
ig.plot(karate, **visual_style, target=ax) 

我收到以下错误,

TypeError:应为 str、bytes 或 os.PathLike 对象,而不是 AxesSubplot

谁能解释一下我做错了什么? 谢谢!

所以python-igraph的pip版本是0.8.3。您所指的文档是 master 分支。你可以看看文件here and note that matplotlib is not anywhere in the code, but if you look at the master branch here 实现是否存在。如果您想要该功能,那么您可以从源代码构建,或者等待下一个版本。