如何在 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
谁能解释一下我做错了什么?
谢谢!
我有一个 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
谁能解释一下我做错了什么? 谢谢!