简体   繁体   中英

How can draw a graph by networkx by giving the edges order to draw?

I want to plot a graph by networkx by edges order. In my data set there are many transport alternative but since the buses are dominant the are means can not be seen. How can I plot order edges on top of the buses?

colors_p = nx.get_edge_attributes(net_p, 'color').values()
ax2 = fig.add_subplot(1, 3, 2)
nx.draw_networkx(net_p, ax=ax2,pos=nx.get_node_attributes(net_p, 'pos'), with_labels=False, node_size=0.5,
                     alpha=0.5, node_color = 'black', edge_color = colors_p)


ax2.get_xaxis().set_visible(False)
ax2.get_yaxis().set_visible(False)
proxies = [make_proxy(clr, lw=5) for clr in edge_types.keys()]
labels = [edge_type for clr, edge_type in edge_types.items()]
ax2.set_title('pspace')
plt.legend(proxies, labels);

在此处输入图像描述

Instead of calling nx.draw_networkx() that draws the graph the way it finds suitable, you can draw the chart element-wise.

Start by extracting a subset of edges (say, the "rail" edges) and plotting them with nx.draw_networkx_edges() . Then extract the "tram" edges and again plot them with nx.draw_networkx_edges() . Eventually, plot the "bus" edges with the same function - they will be on top of everything else.

Finally, draw the nodes with nx.draw_networkx_nodes() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM