如何根据networkx中的节点绘制特定边缘的颜色?

时间:2020-03-19 11:39:13

标签: python matplotlib networkx social-networking

我是Python的新手。 我有一个Louvain聚集图,并且我希望图的边缘颜色跟随其节点的颜色。 这是我的代码:

{{ route('employee.profile', user_id) }}

通过将color参数更改为类似的颜色,我只能将箭头绘制为单一颜色

import matplotlib.pyplot as plt import matplotlib.cm as cm import matplotlib.colors as mcolors import numpy as np partition_louvain = community.best_partition(G) size = float(len(set(partition_louvain.values()))) pos = nx.spring_layout(G) count = 0. communities_louvain = [] cmap=mymap #cmap = cm.get_cmap("BlueRedGreen") for com in set(partition_louvain.values()): count = count + 1. list_nodes = [nodes for nodes in partition_louvain.keys() if partition_louvain[nodes] == com] communities_louvain.append(list_nodes) nx.draw_networkx_nodes(G, pos, list_nodes, node_size=20,connectionstyle='arc3', node_color=cmap(count / size)) #''' cmap2 = cm.get_cmap("jet") #norm = plt.Normalize(pos[e[0]].min(), pos[e[0]].max()) ax = plt.gca() for e in G.edges: norm = plt.Normalize(pos[e[0]].min(), pos[e[0]].max()) cmap2 = cm.get_cmap("jet") ax.annotate("", xy=pos[e[0]], xycoords='data', xytext=pos[e[1]], textcoords='data', arrowprops=dict(arrowstyle="->", color=cmap2(norm(pos[e[0]])), shrinkA=5, shrinkB=5, patchA=None, patchB=None, connectionstyle="arc3,rad=rrr".replace('rrr',str(0.3*e[2]) ), ), ) plt.show()

0 个答案:

没有答案