igraph

Create weighted igraph Graph from numpy summetric 2D array as adjacency matrix

陌路散爱 提交于 2021-02-19 05:36:12
问题 I am having a numpy 2D array, with the values representing the weights of edges between nodes. The matrix is symmetric, and I take the diagonal to be zero. I don't find an example of how to convert this matrix into igraph Graph object. I've tried the following approach, but it doesn't work: import numpy as np import igraph def symmetrize(a): return a + a.T - 2*np.diag(a.diagonal()) A = symmetrize(np.random.random((100,100))) G = igraph.Graph.Adjacency(A.tolist()) 回答1: Use Graph.Weighted

How can I enable `cairo` backend while plotting `igraph` objects on matplotlib?

删除回忆录丶 提交于 2021-02-11 13:31:23
问题 I'm using Jupyter Notebook and trying to make graphs of igraph appear on matplotlib plots. I've found that one of possible solutions is to create GraphArtist class class that draws igraph graphs but, unfortunately, only Cairo-based backends are supported. When I try to use it, no plot is displayed import matplotlib matplotlib.use("cairo") fig = plt.figure() ax = plt.gca() plt.plot(range(10), [i**1.5 for i in range(10)]) #a simplified version of my diagram plt.show() and I get this warning:

How can I enable `cairo` backend while plotting `igraph` objects on matplotlib?

馋奶兔 提交于 2021-02-11 13:29:56
问题 I'm using Jupyter Notebook and trying to make graphs of igraph appear on matplotlib plots. I've found that one of possible solutions is to create GraphArtist class class that draws igraph graphs but, unfortunately, only Cairo-based backends are supported. When I try to use it, no plot is displayed import matplotlib matplotlib.use("cairo") fig = plt.figure() ax = plt.gca() plt.plot(range(10), [i**1.5 for i in range(10)]) #a simplified version of my diagram plt.show() and I get this warning:

Assign colors to communities in igraph

瘦欲@ 提交于 2021-02-10 20:08:16
问题 I am using the fastgreedy.community detection algorithm in igraph to produce communities in R. The code returns 12 communities, however they are difficult to indentify when plotting because it returns a plot with a limited number of colours. How can I plot this graph with tweleve distinct colours? l2 <- layout.fruchterman.reingold(largest.component) ebc.g05 <- fastgreedy.community(largest.component) plot(largest.component, layout=l2, vertex.color=membership(ebc.g05), vertex.size=2, vertex

Assign colors to communities in igraph

微笑、不失礼 提交于 2021-02-10 20:01:08
问题 I am using the fastgreedy.community detection algorithm in igraph to produce communities in R. The code returns 12 communities, however they are difficult to indentify when plotting because it returns a plot with a limited number of colours. How can I plot this graph with tweleve distinct colours? l2 <- layout.fruchterman.reingold(largest.component) ebc.g05 <- fastgreedy.community(largest.component) plot(largest.component, layout=l2, vertex.color=membership(ebc.g05), vertex.size=2, vertex

Check which community a node belongs in louvain community detection

♀尐吖头ヾ 提交于 2021-02-10 15:48:26
问题 So I have run louvain detection on my dataset and returns a bunch of communities with nodes included. My question is, given a node, how do you find which community it belongs to? Thanks. 回答1: The community for each node is stored in the membership component of the result. library(igraph) set.seed(1234) G = erdos.renyi.game(16, 0.22) C = cluster_louvain(G) plot(G, vertex.color=rainbow(3,alpha=0.4)[C$membership]) 来源: https://stackoverflow.com/questions/52245816/check-which-community-a-node

Check which community a node belongs in louvain community detection

人盡茶涼 提交于 2021-02-10 15:47:52
问题 So I have run louvain detection on my dataset and returns a bunch of communities with nodes included. My question is, given a node, how do you find which community it belongs to? Thanks. 回答1: The community for each node is stored in the membership component of the result. library(igraph) set.seed(1234) G = erdos.renyi.game(16, 0.22) C = cluster_louvain(G) plot(G, vertex.color=rainbow(3,alpha=0.4)[C$membership]) 来源: https://stackoverflow.com/questions/52245816/check-which-community-a-node

two column bipartite layout with igraph

China☆狼群 提交于 2021-02-10 15:28:35
问题 I'm trying to plot a bipartite graph, but with two columns; the function manual states that layout_as_bipartite() "Minimize[s] edge-crossings in a simple two-row (or column) layout for bipartite graphs." Trying with the example, I can only get two row graphs: library(igraph) library(dplyr) # Random bipartite graph inc <- matrix(sample(0:1, 50, replace = TRUE, prob=c(2,1)), 10, 5) g <- graph_from_incidence_matrix(inc) plot(g, layout = layout_as_bipartite, vertex.color=c("green","cyan")[V(g)

How to rotate igraph network plot?

纵然是瞬间 提交于 2021-02-10 06:14:37
问题 I'm trying to rotate the R package based igraph network plot. In the igraph guidebook not enough explanation how to use R code tk_rotate(tkp.id, degree = NULL, rad = NULL) 回答1: For the R package igraph according to the documentation: the tk_rotate rotates the figure, its parameter can be given either in degrees or in radians. Of particular note is the argument tkp.id . Make sure you assign the tkplot window to this value so you can reference it as the tkp.id in the function. tkp.id The id of

How to rotate igraph network plot?

坚强是说给别人听的谎言 提交于 2021-02-10 06:11:31
问题 I'm trying to rotate the R package based igraph network plot. In the igraph guidebook not enough explanation how to use R code tk_rotate(tkp.id, degree = NULL, rad = NULL) 回答1: For the R package igraph according to the documentation: the tk_rotate rotates the figure, its parameter can be given either in degrees or in radians. Of particular note is the argument tkp.id . Make sure you assign the tkplot window to this value so you can reference it as the tkp.id in the function. tkp.id The id of