对于常规的GraphPlot
,您将需要一个稍微复杂的解决方案,使用EdgeRenderingFunction
(文档 http://reference.wolfram.com/mathematica/ref/EdgeRenderingFunction.html)。假设您有一个邻接矩阵,其中元素也是(方向)权重。
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"}
以下内容满足您的需要。技巧是使用以下部分引用回邻接矩阵#2
在零件规格内,引用正确的元素nums
,以及Mean[#1]
将标签定位在边缘的中点。插槽#1
似乎保存了顶点的坐标。
GraphPlot[lilnums, DirectedEdges -> True,
VertexRenderingFunction -> ({White, EdgeForm[Black], Disk[#, .04],
Black, Text[names[[#2]], #1]} &),
EdgeRenderingFunction -> ({AbsoluteThickness[2], Red,
Arrowheads[0.02], Arrow[#1, 0.05], Black,
Text[Round@ Abs[(lilnums[[#2[[1]], #2[[2]]]] +
lilnums[[#2[[2]], #2[[1]]]])], Mean[#1],
Background -> Yellow]} &), VertexLabeling -> True,
ImageSize -> 600,
PlotLabel -> Style["Plot Label", Bold, 14, FontFamily -> "Arial"]]