2

I am using networkx to plot graph in python. However, my output is too dense. Is there any ways to sparse the graph? Below is my command in python.Thanks

    pos=nx.spring_layout(self.G)
    nx.draw_networkx_nodes(self.G,pos)
    edge_labels=dict([((u,v,),d['weight'])
             for u,v,d in self.G.edges(data=True)])
    nx.draw_networkx_labels(self.G,pos, font_size=20,font_family='sans-serif')
    nx.draw_networkx_edges(self.G,pos)
    plt.axis('off')
    #nx.draw_networkx_labels(self.G,pos, font_size=20,font_family='sans-serif')
    nx.draw_networkx_edge_labels(self.G,pos,edge_labels=edge_labels)
    nx.draw(self.G,pos, edge_cmap=plt.cm.Reds)

    plt.show()

sample graph

2 Answers 2

2

You can also try Graphviz via PyDot (I prefer this one) or PyGraphviz.

In case you are interested in a publication-ready result, you can use the toolchain networkx -> pydot + dot -> dot2tex + dot -> dot2texi.sty -> TikZ. Instead of this fragile toolchain, you can alternatively export directly to TikZ with nx2tikz (I've written it, so I'm biased) and use the graph layout algorithms that have been relatively recently added to TikZ.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for sharing your experience
0

After I check some information from the documentation here: http://networkx.github.io/documentation/latest/reference/drawing.html#module-networkx.drawing.layout

I changed the format of layout to

pos=nx.circular_layout(self.G, scale=5)

and it works! enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.