简体   繁体   English

如何通过networkx通过给出边缘顺序来绘制图形?

[英]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.我想 plot 按边缘顺序按 networkx 的图。 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? plot 如何在公共汽车顶部订购边缘?

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.您可以按元素绘制图表,而不是调用nx.draw_networkx()以它认为合适的方式绘制图表。

Start by extracting a subset of edges (say, the "rail" edges) and plotting them with nx.draw_networkx_edges() .首先提取边的子集(例如,“铁路”边)并使用nx.draw_networkx_edges()绘制它们。 Then extract the "tram" edges and again plot them with nx.draw_networkx_edges() .然后使用nx.draw_networkx_edges()提取“电车”边缘并再次 plot 它们。 Eventually, plot the "bus" edges with the same function - they will be on top of everything else.最终,plot 与相同的 function 的“总线”边缘 - 它们将位于其他一切之上。

Finally, draw the nodes with nx.draw_networkx_nodes() .最后,使用nx.draw_networkx_nodes()绘制节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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