我正在尝试使用色彩映射根据节点属性为networkx中的节点着色。我想知道色彩图的中点如何设置为零?
这是我目前的示例代码:
import networkx as nx
from matplotlib import pyplot as plt
g=nx.Graph()
g.add_nodes_from(['A','B','C','D','E'])
g.add_edges_from([('A','B'),('B','C'),('B','D')])
nodes=g.nodes()
success_factor={'A':-1,'B':0,'C':7,'D':-2,'E':6}
nx.set_node_attributes(g, success_factor, 'success_factor')
success_color = [nx.get_node_attributes(g, 'success_factor')[v] for v in g]
pos=nx.spring_layout(g)
plt.figure()
ec = nx.draw_networkx_edges(g, pos=pos, alpha=0.8)
nc = nx.draw_networkx_nodes(g, pos=pos, nodelist=nodes, node_color=success_color, cmap=plt.cm.seismic)
ax = plt.gca()
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="2%", pad=0.05)
plt.colorbar(nc, cax=cax)
plt.show()