igraph

Plotting communities with python igraph

好久不见. 提交于 2019-11-29 14:30:30
问题 I have a graph g in python-igraph. I can get a VertexCluster community structure with the following: community = g.community_multilevel() community.membership gives me a list of the group membership of all the vertices in the graph. My question is really simple but I haven't found a python-specific answer on SO. How can I plot the graph with visualization of its community structure? Preferably to PDF, so something like layout = g.layout("kk") plot(g, "graph.pdf", layout=layout) # Community

Perform union of graphs based on vertex names Python igraph

走远了吗. 提交于 2019-11-29 11:39:53
This issue has been filed on github something like 6 months ago, but since it has not yet been fixed I'm wondering whether there is a quick fix that I am missing. I want to merge two graphs based on their names: g1 = igraph.Graph() g2 = igraph.Graph() # add vertices g1.add_vertices(["A","B"]) g2.add_vertices(["B","C","D"]) for vertex in g1.vs: print vertex.index 0 1 for vertex in g2.vs: print vertex.index 0 1 2 However when I perform the union, igraph uses the vertex IDs rather than the names, so I end up with three vertices instead of four (if it was based on names). I guess that because B

How do I lengthen edges in an igraph network plot (layout=fruchterman.reingold)?

徘徊边缘 提交于 2019-11-29 11:04:00
问题 Trying to do a network plot in R. How do I lengthen edges in a network graph using IGraph? I actually want to use the fruchterman-reingold layout. Is there some way I can make that force-based algorithm "springier" so that my vertices are further apart? thanks. 回答1: You can control the Fruchterman-Reingold algorithm using the layout.fruchterman.reingold function. see: help('layout.fruchterman.reingold') . A setup that I often use and gets you a little more spacing is: l <- layout.fruchterman

Get contagion chain from adjacency matrix, r, igraph

柔情痞子 提交于 2019-11-29 10:25:14
问题 Q.I have a erdos.reyni graph. I infect a vertex and want to see what sequence of vertices the disease would follow? igraph has helful functions like get.adjacency(), neighbors(). Details. This is the adjacency matrix with vertex names instead of 0,1 flags and i'm trying to get the contagion chain out of it. Like the flow/sequence of an epidemic through a graph if a certain vertex is infected. Let's not worry about infection probabilities here (assume all vertices hit are infected with

Find distance of route from get.shortest.paths()

匆匆过客 提交于 2019-11-29 09:54:17
问题 I'm using the igraph package in R to do something rather simple: Calculate the shortest distance between two nodes in my network. Is there a straightforward way to extract the distance of a path calculated via get.shortest.paths() ? Here is some reproducible code that exemplifies my problem: ## reproducible code: df2 = rbind(c(234,235,21.6), c(234,326,11.0), c(235,241,14.5), c(326,241,8.2), c(241,245,15.3), c(234,245,38.46)) df2 = as.data.frame(df2) names(df2) = c("start_id","end_id","newcost

Specified edge lengths on networkx/igraph (Python)

心不动则不痛 提交于 2019-11-29 09:22:51
问题 I wanted to visualize a network with the data I have and would like to graph them with specific edge lengths. I use Python, and I've tried networkx and igraph to plot but all seem to assign fixed edge lengths. a.) I wonder if I did the codes wrong or the packages aren't really capable. How do you properly implement specified edge lengths for networkx or igraph? b.) If networkx and igraph can't do it, what package could you possibly suggest? (Preferably one that can carry over 80 thousand

Visualizing distance between nodes according to weights - with R

喜欢而已 提交于 2019-11-29 07:14:38
I'm trying to draw a graph where the distance between vertices correspond to the edge weights* and I've founde that in graphviz there is a way to draw such graph. Is there a way to do this in R with the igraph package (specfically with graph.adkacency)? Thanks, Noam (as once have been asked: draw a graph where the distance between vertices correspond to the edge weights ) This is not possible as you need triangle equality for every triangle to be able to plot such an object. So you can only approximate it. For this you can use "force embedded" algorithms. There are a few in igraph. The one I

using graph.adjacency() in R

岁酱吖の 提交于 2019-11-29 07:08:39
I have a sample code in R as follows: library(igraph) rm(list=ls()) dat=read.csv(file.choose(),header=TRUE,row.names=1,check.names=T) # read .csv file m=as.matrix(dat) net=graph.adjacency(adjmatrix=m,mode="undirected",weighted=TRUE,diag=FALSE) where I used csv file as input which contain following data: 23732 23778 23824 23871 58009 58098 58256 23732 0 8 0 1 0 10 0 23778 8 0 1 15 0 1 0 23824 0 1 0 0 0 0 0 23871 1 15 0 0 1 5 0 58009 0 0 0 1 0 7 0 58098 10 1 0 5 7 0 1 58256 0 0 0 0 0 1 0 After this I used following command to check weight values: E(net)$weight Expected output is somewhat like

Lots of edges on a graph plot in python

萝らか妹 提交于 2019-11-29 06:22:54
I have following script: import pandas as pd from igraph import * df_p_c = pd.read_csv('data/edges.csv') ... edges = list_edges vertices = list(dict_case_to_number.keys()) g = Graph(edges=edges, directed=True) plot(g, bbox=(6000, 6000)) I have 2300 edges with rare connection. This is my plot of it: And here are zooms of a few parts of it: This plot is not readable because the distance between edges is too small. How can I have a bigger distance between edges? Only edges from the same 'family' have small distance. Is there any other way to improve plots with a lot of edges? I'm looking for any

How to solve AttributeError when importing igraph?

北城以北 提交于 2019-11-29 05:54:38
When I import the igraph package in my project, I get an AttributeError. This only happens in the project directory: [12:34][~]$ python2 Python 2.7.1 (r271:86832, Apr 15 2011, 12:09:10) [GCC 4.5.2 20110127 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import igraph >>> [12:34][~]$ cd projectdir/ [12:34][projectdir]$ python2 Python 2.7.1 (r271:86832, Apr 15 2011, 12:09:10) [GCC 4.5.2 20110127 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import igraph Traceback (most recent call last): File