igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] graph from an adjacency matrix


From: Tamas Nepusz
Subject: Re: [igraph] graph from an adjacency matrix
Date: Wed, 25 Feb 2015 10:32:56 +0100
User-agent: Mutt/1.5.23 (2014-03-12)

Hi Jan,

> I have different datasets- the smallest networks consist of 80 nodes, the
> largest even 10,000 (yes I have a lot of RAM), but I'm happy to only
> visualise the small ones. At the moment I've got a numpy matrix, but I can
> convert it into a list of lists or anything else that is needed.
> [...] And additionally I have a list (or numpy array) with node labels, and
> another list with binary values which I would like to use to specify the node
> colour.

Then it is probably as simple as:

import igraph
import numpy

# ...create your NumPy matrix in m...

# if you want to keep only edges with a weight above a certain cutoff:
m[m < cutoff] = 0.0

# create the graph
g = igraph.Graph.Weighted_Adjacency(m)

# construct a layout
layout = g.layout_fruchterman_reingold(weights=g.es["weight"])

# construct the plot settings
plot_settings = dict(
        layout=layout,
        edge_width=igraph.rescale(g.es["weight"], out_range=(0.0, 5.0)),
        vertex_label=any_list_of_strings,
        vertex_color=["red" if value else "blue" for value in 
any_list_of_booleans]
)

# plot the graph
plot(g, **plot_settings)

See the documentation of Graph.Weighted_Adjacency(),
Graph.layout_fruchterman_reingold(), Graph.__plot__() and rescale() for more
information.

All the best,
Tamas



reply via email to

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