如何绘制不同边颜色的相同节点对应两个不同的图?

发布于 2024-09-15 05:16:42 字数 112 浏览 0 评论 0原文

希望我的问题之前没有被问过。我有两个图,它们的节点相同,但边不同。我想在一张图中绘制两个图。这意味着我有相同的节点,但有两种不同的边缘颜色。但它给了我两个不同的图表。我怎样才能将它们放在一张图中但边缘颜色不同?

Hope my question has not asked before. I have two graphs, which nodes are the same in both of them but edges are different. I want to draw both of graphs in one plot. Which means I have the same nodes, but with two different edge colours. But it gives me two different graphs. How could I have them in one graph but with different edge colours?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亚希 2024-09-22 05:16:43

如果您使用 Python、NetworkX 和 Matplotlib,那么您可以执行类似的操作,其中您有两个具有相同节点集的图形,因此您首先绘制节点,然后用不同颜色绘制两组边。

import networkx as nx  

G=nx.gnm_random_graph(10,20)  
G2=nx.gnm_random_graph(10,20)  
pos=nx.spring_layout(G)  

nx.draw_networkx_nodes(G,pos,node_size=80) 

nx.draw_networkx_edges(G,pos,edge_color='r')  
nx.draw_networkx_edges(G2,pos,edge_color='b')  

请注意相同端点之间不同颜色的边缘,它们将无法区分。

If you are using Python, NetworkX and Matplotlib then you can do something like this, where you have two graphs with the same set of nodes and so you draw first the nodes and then the two set of edges in different colors.

import networkx as nx  

G=nx.gnm_random_graph(10,20)  
G2=nx.gnm_random_graph(10,20)  
pos=nx.spring_layout(G)  

nx.draw_networkx_nodes(G,pos,node_size=80) 

nx.draw_networkx_edges(G,pos,edge_color='r')  
nx.draw_networkx_edges(G2,pos,edge_color='b')  

Take care with edges of different colors between the same endpoints, they will be indistinguishable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文