因此,我正在Python中使用networkX生成社区地图,现在我想为其主要社区标记每个节点。这是我使用的代码:
parts = community.best_partition(G_fb)
values = [parts.get(node) for node in G_fb.nodes()]
plt.axis("off")
nx.draw_networkx(G_fb, pos = spring_pos, cmap = plt.get_cmap("jet"), node_color = values, node_size = 35, with_labels = False)
有人知道如何标记此信息吗?
答案 0 :(得分:1)
您可以使用networkx的set_node_attribute功能。只需根据您的networkx版本获得正确的语法(我正在使用2.1)
class Review extends Eloquent {
public function relatedGallery()
{
$this->hasOne('Gallery', 'foreign_id', 'local_id');
}
}
class Gallery extends Eloquent {
public function relatedReviews()
{
$this->hasMany('Review', 'foreign_id', 'local_id');
}
}
$gallery = Gallery::with('relatedReviews')->find($id);
Will bring the object Gallery with
$gallery->id
gallery->name
...
$gallery->relatedReviews // array containing the related Review Objects
更新根据您的评论,您收到一个错误消息,因为您的节点列表中没有编号为import networkx as nx
import community
G = nx.erdos_renyi_graph(30, 0.05)
#Compute the partition
partition = community.best_partition(G)
nx.set_node_attributes(G, partition, 'best_community')
#Then you access each node to get the property
my_nodes = G.nodes()
my_nodes[0]
#{ 'best_community' : 0 }
的节点,请尝试使用0
中的任何节点,例如data