networkx

Reduce edges in a MultiDiGraph

Reduce edges in a MultiDiGraph Question: I’ve a MultiDiGraph in which there are some edges that I need remove. import networkx as ntx import matplotlib.pyplot as plt edges = [ (6, 7), (7, 6), (7, 11), (11, 7), (11, 8), (8, 11), (8, 9), (9, 8), (9, 5), (5, 9), (5, 10), (10, 5), (10, …

Total answers: 1

How to label edges and avoid the edge overlapping in MultiDiGraph/DiGraph? (Networkx)

How to label edges and avoid the edge overlapping in MultiDiGraph/DiGraph? (Networkx) Question: Here is my code now G = nx.from_pandas_edgelist(data, source=’grad’, target=’to’, edge_attr=’count’, create_using=nx.DiGraph()) weight = nx.get_edge_attributes(G, ‘count’) pos = nx.shell_layout(G, scale=1) nx.draw_networkx_nodes(G, pos, node_size=300, node_color=’lightblue’) nx.draw_networkx_labels(G, pos=pos, font_color=’red’) nx.draw_networkx_edges(G, pos=pos, edgelist=G.edges(), edge_color=’black’, connectionstyle=’arc3, rad = 0.1′) nx.draw_networkx_edge_labels(G, pos=pos, edge_labels=weight) plt.show() and the Result …

Total answers: 1

networkx directed graph can't add weight in the middle of the edges from pandas df

networkx directed graph can't add weight in the middle of the edges from pandas df Question: My dataframe columns are A,B,Weight. Around 50 rows Here is my code G = nx.from_pandas_edgelist(df, source=’A’, target=’B’, create_using=nx.DiGraph()) weight = nx.get_edge_attributes(G, ‘Weight’) pos = nx.circular_layout(G, scale=1) nx.draw(G, pos, with_labels=True) nx.draw_networkx_nodes(G, pos, node_size=300) nx.draw_networkx_edges(G, pos=pos, edgelist=G.edges(), edge_color=’black’) nx.draw_networkx_labels(G, pos=pos, edge_labels=weight) …

Total answers: 1

Networkx KeyError: 'source' with from_pandas_edgelist for undirected edgelist

Networkx KeyError: 'source' with from_pandas_edgelist for undirected edgelist Question: I have an edgelist in a pandas dataframe that looks like this: topic neighbor 0 K Kl 1 K Pr 2 Kl TS 3 Pr Kl 4 Pr Pr When I turn this into a Graph (using networkx as nx) with G = nx.from_pandas_edgelist(df) it gives …

Total answers: 2

Combining list of lists based on value in python

Combining list of lists based on value in python Question: The topic was raised due to dealing with some graph problems. So I’m receiving information about graph structure via stdin and input looks like this: Number of Edges ID of NodeN1 Id of NodeN2 ID of NodeN3 Id of NodeN4 ID of NodeN5 Id of …

Total answers: 1

Draw specific edges in graph in NetworkX

Draw specific edges in graph in NetworkX Question: I have a graph looking like this: By default, drawing the graph will include all nodes and edges, but I need to draw some specific edges using an array of connected nodes like this: [ [‘A’, ‘C’, ‘B’, ‘A’], [‘A’, ‘E’, ‘D’, ‘F’, ‘A’], [‘A’, ‘H’, ‘G’, …

Total answers: 1

Adding weighted directed edges to the networkx plot with an arrow from source to destination

Adding weighted directed edges to the networkx plot with an arrow from source to destination Question: import networkx as nx import numpy as np import matplotlib.pyplot as plt import pylab plt.rcParams[‘figure.figsize’] = [10, 10] G = nx.DiGraph() G.add_edges_from([(‘A’, ‘B’),(‘C’,’D’),(‘G’,’D’)], weight=1) G.add_edges_from([(‘D’,’A’),(‘D’,’E’),(‘B’,’D’),(‘D’,’E’)], weight=2) G.add_edges_from([(‘B’,’C’),(‘E’,’F’)], weight=3) G.add_edges_from([(‘C’,’F’)], weight=4) nodeopt = { ‘node_color’: ‘white’, ‘node_size’: 3500, ‘node_shape’: ‘o’, …

Total answers: 2

How do I add weights for edges, when I specified multiple edges, not just 1 specific edge? Networkx

How do I add weights for edges, when I specified multiple edges, not just 1 specific edge? Networkx Question: For the following code: import networkx as nx import matplotlib.pyplot as plt G = nx.DiGraph() #Set 1 G.add_edges_from([(‘A’,’B’),(‘A’,’C’),(‘C’,’B’)]) #Set 2 G.add_edges_from([(‘D’,’A’),(‘D’,’B’),(‘D’,’C’)]) #Set 3 G.add_edges_from([(‘E’,’D’),(‘E’,’B’),(‘E’,’C’)]) pos = nx.spring_layout(G) nx.draw_networkx_nodes(G,pos, node_size=500, node_color = ‘green’) nx.draw_networkx_edges(G,pos, edgelist = G.edges()) …

Total answers: 1

Creating a network using classes for defining nodes

Creating a network using classes for defining nodes Question: I am having some issues trying to use class objects as nodes in a graph. I am creating two classes of agents that I would like to use as nodes in a random graph (e.g. Erdos Renyi). class man(Agent): def __init__(self): self.m = np.random.normal(0.5, 0.1) self.n= …

Total answers: 1