How Can I Specify An Exact Output Size For My Networkx Graph?
The above is the output of my current graph. However, I have yet to manage what I am trying to achieve. I need to output my graph in a larger size so that each node/edge can be vi
Solution 1:
You could try either smaller nodes/fonts or larger canvas. Here is a way to do both:
import matplotlib.pyplot as plt
import networkx as nx
G = nx.cycle_graph(80)
pos = nx.circular_layout(G)
# default
plt.figure(1)
nx.draw(G,pos)
# smaller nodes and fonts
plt.figure(2)
nx.draw(G,pos,node_size=60,font_size=8)
# larger figure size
plt.figure(3,figsize=(12,12))
nx.draw(G,pos)
plt.show()
Solution 2:
Since it seems that your network layout is too "messy", you might want to try different graph layout algorithms and see which one suits you best.
nx.draw(G)
nx.draw_random(G)
nx.draw_circular(G)
nx.draw_spectral(G)
nx.draw_spring(G)
Also, if you have too many nodes (let's say some thousands) visualizing your graph can be a problem.
Solution 3:
you can increase the size of the plot as well as set the dpi. If dpi is lowered that nodes would spread out more.
G = nx.Graph()
# Add edges
fig = plt.figure(1, figsize=(200, 80), dpi=60)
nx.draw(G, with_labels=True, font_weight='normal')
Post a Comment for "How Can I Specify An Exact Output Size For My Networkx Graph?"