Julia GraphPlot 中有两个(或更多)节点标签集,可能使用 Compose?

JKH*_*KHA 6 label graph julia plots.jl

以下是 Julia Discourse 的最小工作代码:

using LightGraphs
using GraphPlot
using Colors

g = graphfamous("karate")

membership = [1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,2,1,1,2,1,2,1,2,1,1,1,1,2,1,1,2,1,1,1]
nodelabels = 1:34
nodecolor = [colorant"lightgrey", colorant"orange"]
nodefillc = nodecolor[membership]

colors = [colorant"lightgray" for i in  1:78]
colors[42] = colorant"orange"

gplot(g, nodefillc=nodefillc, layout=circular_layout, edgestrokec=colors, nodelabel=nodelabels)
Run Code Online (Sandbox Code Playgroud)

其产生: 在此输入图像描述

我成功获得了从 1 到 34 的节点标签,但是,我需要为某些特定节点显示另一种类型的标签。例如,某些节点的权重。也就是说,例如,我需要节点 19 的权重为 100,节点 1 的权重为 0.001。

有没有办法显示这样的数据?我可以在 GraphPlot 中找到相关关键字(只有 nodelabel 只接受向量),但我找不到另一个可以用于绘制图形的 Julia 包。

编辑感谢@Dan Getz,在发布到 SE 之前,我有与他建议相同的想法:尝试用格式的字符串标记节点"$i\n $weight" 但是,结果非常令人不满意,正如您在我的一张照片中看到的那样实际图表。橙色的节点 12,与其权重 177.0 分开,\n读起来不太好!

编辑感谢 @Przemyslaw Szufel 也许我的问题可以通过Compose(我实际上已经使用过)来解决,这是GraphPlot. 不幸的是,尽管我和其他人询问过它,但它还是有点没有记录!

在此输入图像描述

Cor*_*lus 1

您可以使用GraphMakie.jl,它也与 (Light) 兼容,Graphs.jl并且可能比 更灵活一些GraphPlot.jl

using Graphs, GraphMakie, Colors

g = smallgraph(:karate)

membership = [1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,2,1,1,2,1,2,1,2,1,1,1,1,2,1,1,2,1,1,1]
nodelabels = repr.(collect(1:34))
nodecolor = [colorant"lightgrey", colorant"orange"]
nodefillc = nodecolor[membership]

colors = [colorant"lightgray" for i in  1:78]
colors[42] = colorant"orange"

fig = Figure(resolution=(500,500))
ax = Axis(fig[1,1])
pos = Shell()(g) # = circular layout
graphplot!(ax, g, 
    layout=_->pos,
    edge_color=colors, 
    node_color=nodefillc, 
    node_size=30, 
    nlabels=nodelabels,
    nlabels_align=(:center, :center)
)
hidedecorations!(ax)
hidespines!(ax)    

# add additional annotation to node 17
weightOffset = Point2(0, 0.045)
text!(ax, "0.001", position=pos[17] - weightOffset, space=:data, align=(:center, :top), fontsize=10)

display(fig)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述