Plotting readable graph with labels in networkx
Plotting readable graph with labels in networkx
I want to plot a graph in networkx with 283 nodes and with labels. I don't know if it's even possible to do so, but i try with the following code:
def graph(list_edges,i):
plt.figure(dpi=3000)
plt.tight_layout()
plt.title('Siatka nr '.format(i))
edges=list_edges
G=nx.Graph()
G.add_edges_from(edges)
pos = nx.spring_layout(G)
nx.draw(G,pos,edge_color='black',width=1,linewidths=1,
node_size=5,node_color='pink',alpha=0.9,
#labels=node:node for node in G.nodes(),
font_size=3)
plt.savefig("plot__tr__.png".format(i), dpi=3000)
graph(edges,0)
I've tried to play with dpi, but i doesn't help.
With commented out labels I get:
Is it somehow possible to force better distribution of nodes and add labels on one image and keep readbility? Or maybe there is an option to plot whole image in parts (which would also be helpful in my situation)?
1 Answer
1
Hey I am unsure about how to plot the whole image in parts or how to get a better distribution of nodes, however; if you want to add labels to your nodes, this should solve your problem:
- Add with_labels=True
as an argument when you draw your network. Hope this helps.
with_labels=True
e.g
nx.draw(G, with_labels=True)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.