简体   繁体   English

用不同的 colors 绘制“标记组”

[英]Plotting “mark groups” with different colors

I am very new to igraph, and have been plotting out a project of mine.我对 igraph 很陌生,并且一直在策划我的一个项目。 In my python code I used the:在我的 python 代码中,我使用了:

igraph.VertexClustering.FromAttribute(graph, attribute)

to identify the groups.来识别组。

The problem is the coloring of this VertexCluster.问题是这个 VertexCluster 的着色。 When using the VertexCluster as “mark_groups” for the visual style, the groups are grey.当使用 VertexCluster 作为视觉样式的“mark_groups”时,组是灰色的。 Despite using “mark_col”, it does not change.尽管使用了“mark_col”,但它并没有改变。 Example of the grey marked groups灰色标记组的示例

How do I change the colors for mark_groups when using a VertexClustering.FromAttribute?使用 VertexClustering.FromAttribute 时,如何更改 mark_groups 的 colors?

As I don't know the exact code I don't know what's wrong.因为我不知道确切的代码,所以我不知道出了什么问题。 I've just created a working example based on this description我刚刚根据这个描述创建了一个工作示例

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")

使用组的颜色作为边缘

I tried to remove the first line in the for cycle to keep the original colors, but not all the colors was kept that was defined in the g.vs["color"] =... line.我尝试删除 for 循环中的第一行以保留原始 colors,但并非所有 colors 都保留在g.vs["color"] =...行中定义。 I don't know the reason.我不知道原因。 I got this:我懂了:

保持顶点颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM