简体   繁体   English

如何在 matplotlib 轴上 plot 和 iGraph object

[英]How to plot an iGraph object on matplotlib axes

I have an iGraph object and I want to plot it on a Matplotlib axis,我有一个 iGraph object 并且我想 plot 它在 Matplotlib 轴上,

the code for my graph is我的图表的代码是

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

the iGraph documentation says that you can plot inside a Matplotlib axis using, iGraph 文档说您可以在 Matplotlib 轴内使用 plot ,

import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ig.plot(g, target=ax)

source: https://igraph.org/python/doc/tutorial/visualisation.html来源: https://igraph.org/python/doc/tutorial/visualisation.html

however, when I run,然而,当我跑步时,

fig, ax = plt.subplots()
ig.plot(karate, **visual_style, target=ax) 

I get the following error,我收到以下错误,

TypeError: expected str, bytes or os.PathLike object, not AxesSubplot类型错误:预期的 str、字节或 os.PathLike object,而不是 AxesSubplot

Can anyone explain what I am doing wrong please?谁能解释我做错了什么? Thanks!谢谢!

So the pip version of python-igraph is 0.8.3.所以python-igraph的pip版本是0.8.3。 The documentation you're referring to is the master branch.您所指的文档是主分支。 You can look at the file here and note that matplotlib is not anywhere in the code, but if you look at the master branch here the implementation exists.您可以在此处查看文件并注意 matplotlib 不在代码中的任何位置,但如果您查看此处的主分支,则实现存在。 If you want that functionality, then you can build from source, or wait for the next release.如果你想要那个功能,那么你可以从源代码构建,或者等待下一个版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM