[英]Plotting “mark groups” with different colors
我对 igraph 很陌生,并且一直在策划我的一个项目。 在我的 python 代码中,我使用了:
igraph.VertexClustering.FromAttribute(graph, attribute)
来识别组。
问题是这个 VertexCluster 的着色。 当使用 VertexCluster 作为视觉样式的“mark_groups”时,组是灰色的。 尽管使用了“mark_col”,但它并没有改变。 灰色标记组的示例
使用 VertexClustering.FromAttribute 时,如何更改 mark_groups 的 colors?
因为我不知道确切的代码,所以我不知道出了什么问题。 我刚刚根据这个描述创建了一个工作示例
import igraph as ig
import matplotlib.pyplot as plt
g = ig.Graph(edges=[(0, 1), (1, 2), (3, 4), (4, 5)])
g.vs["cluster"] = [0, 0, 0, 1, 1, 1]
g.vs["color"] = ["red", "blue", "blue", "green", "orange", "gold"]
communities = ig.VertexClustering.FromAttribute(g, "cluster")
num_communities = len(communities)
palette = ig.RainbowPalette(n=num_communities)
for i, community in enumerate(communities):
g.vs[community]["color"] = i # Remove this to keep the original colors
community_edges = g.es.select(_within=community)
community_edges["color"] = i
fig, ax = plt.subplots()
ig.plot(
communities,
target=ax,
mark_groups=True,
palette=palette
)
fig.savefig("clusters.png")
我尝试删除 for 循环中的第一行以保留原始 colors,但并非所有 colors 都保留在g.vs["color"] =...
行中定义。 我不知道原因。 我懂了:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.