How to Label Graph Edges with their weights

前端 未结 4 1064
萌比男神i
萌比男神i 2021-02-09 11:57

Warning! I posted the question when Mathematica v 8.0 was the coolest kid. The bug has been solved as of version 9.0.1

The help for EdgeLabels states:

4条回答
  •  伪装坚强ぢ
    2021-02-09 12:32

    EdgeLabels -> "EdgeWeight" still doesn't work in 8.0.4 and no longer seems to be in the documentation. However, here is one solution that does work:

    lilnums = {{0, 2., 1., 3., 0, 6.}, {0, 0, 1., 2., 0, 0}, {1., 8., 0, 2., 0, 2.},
      {10., 13., 7., 0, 0, 10.}, {0, 0, 0, 0, 0, 0}, {4., 1., 1., 2., 2., 0}}
    names = {"AT", "AU", "CA", "CH", "CL", "ES"};
    g = WeightedAdjacencyGraph[names, lilnums /. {0 -> \[Infinity]}, 
      VertexShapeFunction -> "Name" , ImagePadding -> 15];
    SetProperty[g, EdgeLabels -> MapThread[#1 -> #2 &, 
      {EdgeList[g], PropertyValue[g, EdgeWeight]}]]
    

提交回复
热议问题