Hi
I am trying to create a graph with node labels printed outside of nodes. I am able to generate 'offset' as shown below that solve the purpose. However, Sometimes the labels overlaps with edges (Which is undesirable as there are lots of empty spaces around nodes where the corresponding labels can be printed. See the attachment. ). I need to label these nodes in such a way that the labels does not overlap any edge or at least try to minimize overlap as much as possible. As you can see in the attached plot, 'bbbbb' and 'eeeee' overlaps with edges whereas they could have been labeled below also.
I do see function 'label_pos' to position label on edge but was unsuccessful finding similar method for nodes.
import networkx as nx
from networkx.utils import is_list_of_ints, flatten
import matplotlib.pyplot as plt
G=nx.Graph()
G = nx.complete_graph(5)
mapping = {0:'aaaaaaa',1:'bbbbbbb',2:'ccccccc', 3:'dddddddd', 4:'eeeeeeeee'}
G = nx.relabel_nodes(G,mapping)
plt.figure(figsize=(10,10), facecolor="w", frameon=False)
pos = nx.graphviz_layout(G, prog="fdp") #calculate position (x,y) coordinates
nx.draw_networkx_nodes(G,pos,node_size=1200,node_shape='o',node_color='0.75')
nx.draw_networkx_edges(G,pos, width=2,edge_color='b')
#for labeling outside the node
offset =10
pos_labels = {}
keys = pos.keys()
for key in keys:
x, y = pos[key]
pos_labels[key] = (x, y+offset)
nx.draw_networkx_labels(G,pos=pos_labels,fontsize=2)
plt.show()Is there any function in networkx that can deal with such situation? I googled for long with no success.
--
You received this message because you are subscribed to the Google Groups "networkx-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/networkx-discuss/-/CKNFONFuadIJ.
To post to this group, send email to networkx...@googlegroups.com.
To unsubscribe from this group, send email to networkx-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/networkx-discuss?hl=en.