Labeling edges in networkx

Here is an example for ploting edge label in networkx, hope it will help you. import matplotlib.pyplot as plt import networkx as nx edges = [[‘A’, ‘B’], [‘B’, ‘C’], [‘B’, ‘D’]] G = nx.Graph() G.add_edges_from(edges) pos = nx.spring_layout(G) plt.figure() nx.draw( G, pos, edge_color=”black”, width=1, linewidths=1, node_size=500, node_color=”pink”, alpha=0.9, labels={node: node for node in G.nodes()} ) … Read more

large graph visualization with python and networkx

from matplotlib import pylab import networkx as nx def save_graph(graph,file_name): #initialze Figure plt.figure(num=None, figsize=(20, 20), dpi=80) plt.axis(‘off’) fig = plt.figure(1) pos = nx.spring_layout(graph) nx.draw_networkx_nodes(graph,pos) nx.draw_networkx_edges(graph,pos) nx.draw_networkx_labels(graph,pos) cut = 1.00 xmax = cut * max(xx for xx, yy in pos.values()) ymax = cut * max(yy for xx, yy in pos.values()) plt.xlim(0, xmax) plt.ylim(0, ymax) plt.savefig(file_name,bbox_inches=”tight”) pylab.close() … Read more

networkx add_node with specific position

You can use the following approach to set individual node positions and then extract the “pos” dictionary to use when drawing. In [1]: import networkx as nx In [2]: G=nx.Graph() In [3]: G.add_node(1,pos=(1,1)) In [4]: G.add_node(2,pos=(2,2)) In [5]: G.add_edge(1,2) In [6]: pos=nx.get_node_attributes(G,’pos’) In [7]: pos Out[7]: {1: (1, 1), 2: (2, 2)} In [8]: nx.draw(G,pos) … Read more

How to set the output size in GraphViz for the dot format?

Here’s the TL;DR version: To generate a 900 by 1500 pixel PNG image from the graph in foo.gv you can run: dot -Tpng -Gsize=9,15\! -Gdpi=100 -ofoo.png foo.gv to yield an image that is exactly 900 pixels wide or 1500 tall, but not necessarily both; and then: convert foo.png -gravity center -background white -extent 900×1500 final.png … Read more

Draw different color for nodes in networkx based on their node value

import networkx as nx import numpy as np import matplotlib.pyplot as plt G = nx.Graph() G.add_edges_from( [(‘A’, ‘B’), (‘A’, ‘C’), (‘D’, ‘B’), (‘E’, ‘C’), (‘E’, ‘F’), (‘B’, ‘H’), (‘B’, ‘G’), (‘B’, ‘F’), (‘C’, ‘G’)]) val_map = {‘A’: 1.0, ‘D’: 0.5714285714285714, ‘H’: 0.0} values = [val_map.get(node, 0.25) for node in G.nodes()] nx.draw(G, cmap=plt.get_cmap(‘viridis’), node_color=values, with_labels=True, font_color=”white”) … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)