参考Link:
(10)Python利用igraph绘制复杂网络聚类(社区检测)结果图
https://blog.csdn.net/liuhuan323/article/details/78936781

# Python 2.7
from igraph import *
from PIL import Image
colors_type = ["yellow", "red", "green", "coral", "alice blue", "cyan", "pink",
"gray", "blue", "green yellow", "orange", "light blue", "hot pink", "light green", "gold"]
def PlotNetworks(net_file, detected_label, real_label = "Unknown Type"):
## read files
network = Graph.Read_Adjacency(net_file)
Graph.to_undirected(network)
f1 = open(detected_label)
line = f1.readline()
line = line.strip()
str_line = line.split('\t')
dlabel = [int(ele) for ele in str_line]
network.vs["dlabel"] = dlabel
if(real_label != "Unknown Type"):
f2 = open(real_label)
line = f2.readline()
line = line.strip()
str_line = line.split('\t')
rlabel = [int(ele) for ele in str_line]
network.vs["rlabel"] = rlabel
# plot networks
nnodes = len(network.vs)
network.vs["name"] = [str(i+1) for i in range(nnodes)]
layout = network.layout("drl")
visual_style = {}
if(nnodes < 100):
visual_style["vertex_size"] = 22
else:
visual_style["vertex_size"] = 18
visual_style["vertex_label"] = network.vs["name"]
visual_style["layout"] = layout
visual_style["bbox"] = (500,500)
visual_style["margin"] = 20
visual_style["edge_curved"] = 0.3
visual_style["vertex_color"] = [colors_type[i-1] for i in network.vs["dlabel"]]
plot(network, "social_network1.png", **visual_style)
figure1 = Image.open("social_network1.png")
figure1.save("social_network1.bmp")
if(real_label != "Unknown Type"):
visual_style["vertex_color"] = [colors_type[i-1] for i in network.vs["rlabel"]]
plot(network, "social_network2.png", **visual_style)
figure2 = Image.open("social_network2.png")
figure2.save("social_network2.bmp")





void callPython(char *str1, char *str2, char *str3)
{
Py_Initialize();
PyObject *pModule = NULL;
PyObject *pFunc = NULL;
pModule = PyImport_ImportModule("PlotNetworks");
pFunc = PyObject_GetAttrString(pModule, "PlotNetworks");
PyObject *pArgs = PyTuple_New(3);
PyTuple_SetItem(pArgs, 0, Py_BuildValue("s", str1));
PyTuple_SetItem(pArgs, 1, Py_BuildValue("s", str2));
PyTuple_SetItem(pArgs, 2, Py_BuildValue("s", str3));
PyEval_CallObject(pFunc, pArgs);
Py_Finalize();
}

来源:CSDN
作者:Jxufe渣渣斯
链接:https://blog.csdn.net/JxufeCarol/article/details/103999896