[英]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.