如何在networkx.draw_networkx中获取颜色栏?

时间:2018-03-30 09:46:15

标签: python python-3.x matplotlib machine-learning networkx

我正在关系图上执行群集,目前正在使用networkx来查看结果:

G = nx.from_numpy_matrix(X)
layout = nx.fruchterman_reingold_layout(G)
nx.draw_networkx(G, pos=layout, with_labels=True, node_color=predict, cmap=plt.cm.coolwarm, vmin=0, vmax=1)

enter image description here

是否可以获得彩条?只需使用plt.colorbar()就会出错:

  

RuntimeError: No mappable was found to use for colorbar creation. First define a mappable such as an image (with imshow) or a contour set (with contourf).

documentation中没有任何选项。 我也愿意使用另一个包进行可视化,只要它与Python 3兼容。

1 个答案:

答案 0 :(得分:2)

以下是基于空手道俱乐部图表的演示:

pruebas.xml

结果:

enter image description here