How can I convert a two column array to a matrix with counts of occurences?

One way could be to build a graph using NetworkX and obtain the adjacency matrix directly as a dataframe with nx.to_pandas_adjacency. To account for the co-occurrences of the edges in the graph, we can create a nx.MultiGraph, which allows for multiple edges connecting the same pair of nodes: import networkx as nx G = nx.from_edgelist(pair_array, … Read more

Networkx : Convert multigraph into simple graph with weighted edges

One very simple way of doing it is just to pass your multigraph as input to Graph. import networkx as nx G = nx.MultiGraph() G.add_nodes_from([1,2,3]) G.add_edges_from([(1, 2), (1, 2), (1, 3), (2, 3), (2, 3)]) G2 = nx.Graph(G) This will create an undirected graph of your multigraph where multiple edges are merged into single edges. … Read more

How can one modify the outline color of a node In networkx?

UPDATE (3/2019): as of networkx 2.1, the kwargs are forwarded from draw(), so you should be able to simply call draw() with the edge_color kwarg. Ok, this is kind of hacky, but it works. Here’s what I came up with. The Problem networkx.draw() calls networkx.draw_networkx_nodes(), which then calls pyplot.scatter() to draw the nodes. The problem … Read more

How to avoid overlapping when there’s hundreds of nodes in networkx?

You can use interactive graphs by plotly to plot such a large number of nodes and edges. You can change every attribute like canvas size etc and visualize it more easily by zooming other actions. Example: Import plotly import plotly.graph_objects as go import networkx as nx Add edges as disconnected lines in a single trace … Read more

Select network nodes with a given attribute value

Python <= 2.7: According to the documentation try: nodesAt5 = filter(lambda (n, d): d[‘at’] == 5, P.nodes(data=True)) or like your approach nodesAt5 = [] for (p, d) in P.nodes(data=True): if d[‘at’] == 5: nodesAt5.append(p) Python 2.7 and 3: nodesAt5 = [x for x,y in P.nodes(data=True) if y[‘at’]==5]

How do I add a new attribute to an edge in networkx?

You may have a networkx MultiGraph instead of a graph and in that case the attribute setting for edges is a little tricker. (You can get a multigraph by loading a graph with more than one edge between nodes). You may be corrupting the data structure by assigning the attribute G.edge[id_source][id_target][‘type’]= value when you need … Read more