python - 如何在 matplotlib 轴上绘制 iGraph 对象

标签 python 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) 

我收到以下错误,

类型错误:预期的 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/

相关文章:

python - 基于阈值的累计月度 YTD

python - matplotlib 生成的草率 SVG 导致图形中数据点绘图的剪裁不佳

python - Matplotlib - 显示具有代表相同值的多种颜色的图例

python - 在 matplotlib 中绘制值与字符串的关系?

r - 节点不尊重 ggraph/igraph 中的分面

python - 文本语料库的数据结构

Python: "re"模块包含在 "Tkinter"模块中?

r - 在转换矩阵上运行随机游走比 igraph::random_walk() 更有效

python - 如何在pytest中捕获异常后打印消息

R:如何将 osmdata 的运行时间减少为 igraph 转换