【问题标题】:How to plot an iGraph object on matplotlib axes如何在 matplotlib 轴上绘制 iGraph 对象
【发布时间】:2021-05-06 13:24:07
【问题描述】:

我有一个 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 matplotlib igraph


    【解决方案1】:

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

    【讨论】:

    • 这是否意味着我可以使用master分支?抱歉,如果我混淆了参考,但链接的文档是否可以显示它可以完成并且我认为我已经正确地遵循了这些步骤?
    • 如果你从源代码编译你可以,但如果你只是使用 pip 安装你需要等到 pip 上的版本更新为 igraph 的最新版本。
    猜你喜欢
    • 2018-02-11
    • 2020-12-17
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2015-10-05
    • 2016-02-09
    • 2015-03-11
    • 1970-01-01
    相关资源
    最近更新 更多