How to add metadata such as labels to nodes in Graphs.jl?

Hi, I wonder if there some convenient way to add the labels to nodes in a graph, I’m using Graphs.jl currently.

I have try to record the (node Number => label) in a separated dictionary, but I think the order of nodes number will be change if any node removed or added, so, is there any suggestion to attach a label to the node?

Thanks for any suggestion.

The recommended package for that would be MetaGraphsNext.jl, but it is a little rough around the edges. MetaGraphs.jl is an older and more stable but less efficient version

1 Like

Thanks for you help!
I have try both MetaGraphsNext.jl and MetaGraphs.jl, but I met the error:

julia> typeof(g)
SimpleGraph{Int64}   

julia> G = MetaGraph(g)      
ERROR: MethodError: no method matching LightGraphs.SimpleGraphs.SimpleGraph(::SimpleGraph{Int64})     

I have installed the packages as below:(they have entry on JuliaGraphs website)

MetaGraphsNext v0.3.0
MetaGraphs v0.7.1  
Graphs v1.7.1

it is confused, do both packages only work with LightGraphs.jl instead of Graphs.jl currently?

You’re only supposed to use one of these packages at a time. Can you provide a complete reproducible example (with imports) so I can take a look?

It is my stupid mistake, I did load two packages. :upside_down_face:

It works fine now. Thanks for your wonderful pacakge. It saves my time.

1 Like