首页 > 解决方案 > 如何在 matplotlib 轴上绘制 iGraph 对象

问题描述

我有一个 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、字节或 os.PathLike 对象,而不是 AxesSubplot

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

标签: pythonmatplotlibigraph

解决方案


所以python-igraph的pip版本是0.8.3。您所指的文档是主分支。您可以在此处查看文件并注意 matplotlib 不在代码中的任何位置,但如果您查看此处的主分支,则存在实现。如果你想要那个功能,那么你可以从源代码构建,或者等待下一个版本。


推荐阅读