how to draw directed graphs using networkx in python?

后端 未结 6 757
灰色年华
灰色年华 2020-12-04 04:47

I have some nodes coming from a script that I want to map on to a graph. In the below, I want to use Arrow to go from A to D and probably have the edge colored too in (red o

6条回答
  •  一整个雨季
    2020-12-04 05:40

    You need to use a directed graph instead of a graph, i.e.

    G = nx.DiGraph()
    

    Then, create a list of the edge colors you want to use and pass those to nx.draw (as shown by @Marius).

    Putting this all together, I get the image below. Still not quite the other picture you show (I don't know where your edge weights are coming from), but much closer! If you want more control of how your output graph looks (e.g. get arrowheads that look like arrows), I'd check out NetworkX with Graphviz.

    enter image description here

提交回复
热议问题