igraph

All paths of length L from node n using python

女生的网名这么多〃 提交于 2019-11-29 05:21:44
Given a graph G, a node n and a length L, I'd like to collect all (non-cyclic) paths of length L that depart from n. Do you have any idea on how to approach this? By now, I my graph is a networkx.Graph instance, but I do not really care if e.g. igraph is recommended. Thanks a lot! I would just like to expand on Lance Helsten's excellent answer: The depth-limited search searches for a particular node within a certain depth (what you're calling the length L), and stops when it finds it. If you will take a look at the pseudocode in the wiki link in his answer, you'll understand this: DLS(node,

igraph axes xlim ylim plot incorrectly

假如想象 提交于 2019-11-29 04:27:39
if I make a graph g : g <- read.table(text=" A B W 1 55 3 2 55 5 3 99 6 ",header=TRUE) library(igraph) g <- graph.data.frame(g) and matrix of coordinates: y<-1:5 x<-c(0.1,0.1,0.2,0.2,0.8) l<-data.frame(x,y) l<-as.matrix(l) I can plot the graph with node positions according to custom coordinates and plot axes. plot(g,layout=l,rescale=F,axes=TRUE,ylim=c(0,6),xlim=c(0,1)) But the xaxis limits do not function properly and I think are altered by yaxis limits. How can I control the xaxis they way i want for instance keeping it between 0 and 1. i.e. plot(x,y,xlim=c(0,1),ylim=c(0,6)) Is this a bug? If

igraph Graph from numpy or pandas adjacency matrix

北城以北 提交于 2019-11-28 21:16:14
问题 I have an adjacency matrix stored as a pandas.DataFrame : node_names = ['A', 'B', 'C'] a = pd.DataFrame([[1,2,3],[3,1,1],[4,0,2]], index=node_names, columns=node_names) a_numpy = a.as_matrix() I'd like to create an igraph.Graph from either the pandas or the numpy adjacency matrices. In an ideal world the nodes would be named as expected. Is this possible? The tutorial seems to be silent on the issue. 回答1: In igraph you can use igraph.Graph.Adjacency to create a graph from an adjacency matrix

Which layout should I use to get non-overlapping edges in igraph?

时间秒杀一切 提交于 2019-11-28 17:14:54
I am trying to build graphs using tree-like data, where nodes typically split into >2 edges. I have tried various layouts, and I see that the layout.reingold.tilford parameter will generate tree-like graphs with non-bifurcating data. However the outputs are not particularly attractive. I would rather use something like the layout.lgl or layout.kamada.kawai since these produce more radial structures. I cannot see how to change the parameters in R such that these trees have no overlapping edges though. Is this possible? I imported a simple data file in Pajek format, with 355 nodes and 354 edges.

How to create weighted adjacency list/matrix from edge list?

倖福魔咒の 提交于 2019-11-28 17:07:05
My problem is very simple: I need to create an adjacency list/matrix from a list of edges. I have an edge list stored in a csv document with column1 = node1 and column2 = node2 and I would like to convert this to a weighted adjacency list or a weighted adjacency matrix. To be more precise, here's how the data looks like -where the numbers are simply node ids: node1,node2 551,548 510,512 548,553 505,504 510,512 552,543 512,510 512,510 551,548 548,543 543,547 543,548 548,543 548,542 Any tips on how to achieve the conversion from this to a weighted adjacency list/matrix? This is how I resolved to

How can I plot igraph community with defined colors?

狂风中的少年 提交于 2019-11-28 12:22:59
I can use the code below to generate and draw communities: wc <- walktrap.community(subgraph) modularity(wc) membership(wc) layout <-layout.fruchterman.reingold(subgraph) plot(wc, subgraph, layout=layout, vertex.label=NA, vertex.size=5, edge.arrow.size=.2) However, the colors of the communities are automatic, I have two questions: Could I custom the community color? Could I add some text in the community area? Yes, you can do both of those things. Changing the colors of the nodes according to which module they are in (as well as changing the colors of the polygons around the modules) is

Union of igraph objects loses attributes

丶灬走出姿态 提交于 2019-11-28 10:17:10
问题 I have two igraph objects, which have different color attributes. Vertices "A" and "B" in first graph are colored red. Vertices "AA" and "BB" in second graph are colored green. After joining the two, the different colors are lost. library(igraph) graph.1= graph.data.frame(data.frame(start=c("a", "b"), end=c("A", "B"))) V(graph.1)[name%in% c("A", "B")]$color= "red" graph.2= graph.data.frame(data.frame(start=c("a", "b"), end=c("AA", "BB"))) V(graph.2)[name%in% c("AA", "BB")]$color= "green"

R reciprocal edges in igraph in R

↘锁芯ラ 提交于 2019-11-28 08:19:48
问题 I am working with graphs in R. I am currently using igraph and I would like to be able to plot bidirectional edges "reciprocal edges" of a graph. So far I've seen it is possible to plot "bidirectional" graphs but not reciprocal edges, for example: E(1,3) and E(3,1) could potentially be represented as a bidirectional edge <-->, but instead I would like to plot two parallel edges one pointing to the opposite direction of the other || . There exist in Rgraphviz an option when plotting "plot(rEG,

Perform union of graphs based on vertex names Python igraph

空扰寡人 提交于 2019-11-28 05:31:44
问题 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

Lots of edges on a graph plot in python

我们两清 提交于 2019-11-27 23:51:21
问题 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'