我有一个 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)
我收到以下错误,
类型错误:预期的 str、字节或 os.PathLike 对象,而不是 AxesSubplot
谁能解释一下我做错了什么吗? 谢谢!
最佳答案
所以 python-igraph 的 pip 版本是 0.8.3。您所指的文档是 master 分支。你可以查看文件here并注意 matplotlib 不在代码中的任何位置,但是如果您查看 master 分支 here实现存在。如果您想要该功能,那么您可以从源代码构建,或者等待下一个版本。
关于python - 如何在 matplotlib 轴上绘制 iGraph 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66008439/