igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Can not plot community structure


From: Zhige Xin
Subject: [igraph] Can not plot community structure
Date: Fri, 8 Apr 2016 16:23:04 -0700

Hi I tried to plot the community structure by using label propagation algorithm but got some errors. First, the value of modularity is none. Second, it produced IndexError: color index must be non-negative.

My idea:
1. Read from a csv file with the format of weighted adjacency matrix 
2. Convert the data into a graph object in igraph
3. Applying label propagation algorithm to find communities
4. Plot the result

My code is following:

from igraph import *
from numpy import genfromtxt
import numpy as np


my_data = genfromtxt('CBSNews.csv', delimiter=',')
conn_indices = np.where(my_data)
weights = my_data[conn_indices]
edges = zip(*conn_indices)
g = Graph(edges=edges, directed=False)
g.es['weight'] = weights
result = g.community_label_propagation()
print result.modularity
plot(result)

The erros message is:

Traceback (most recent call last):
  File "plot_community.py", line 25, in <module>
    plot(result)
  File "/usr/local/lib/python2.7/site-packages/igraph/drawing/__init__.py", line 475, in plot
    result.show()
  File "/usr/local/lib/python2.7/site-packages/igraph/drawing/__init__.py", line 316, in show
    self.redraw(ctx)
  File "/usr/local/lib/python2.7/site-packages/igraph/drawing/__init__.py", line 269, in redraw
    plotter(ctx, bbox, palette, *args, **kwds)
  File "/usr/local/lib/python2.7/site-packages/igraph/clustering.py", line 509, in __plot__
    return self._graph.__plot__(context, bbox, palette, *args, **kwds)
  File "/usr/local/lib/python2.7/site-packages/igraph/__init__.py", line 3152, in __plot__
    drawer.draw(self, palette, *args, **kwds)
  File "/usr/local/lib/python2.7/site-packages/igraph/drawing/graph.py", line 259, in draw
    vertex_builder = vertex_drawer.VisualVertexBuilder(graph.vs, kwds)
  File "/usr/local/lib/python2.7/site-packages/igraph/drawing/metamagic.py", line 222, in __init__
    values = self._collect_attributes(attr_spec)
  File "/usr/local/lib/python2.7/site-packages/igraph/drawing/metamagic.py", line 340, in _collect_attributes
    result = [transform(x) for x in result]
  File "/usr/local/lib/python2.7/site-packages/igraph/drawing/colors.py", line 93, in get
    raise IndexError("color index must be non-negative")

I do appreciate it if anyone can help.




Best,
Zhige

reply via email to

[Prev in Thread] Current Thread [Next in Thread]