# Edge labels in GraphPlot3D from Adjacency Matrix

I am rendering a family of graphs via GraphPlot3D[AdjacencyMatrix] and I would also like to label the edges. I already use a vertex rendering function to color the vertices.

There are two ways to do this that I'm aware of:

• EdgeLabels -> [Array]

• EdgeRenderingFunction -> {Function}

Is there a simpler way to label the edges, analogous to the "manual" method:

GraphPlot3D[edge -> "label"]

• Could you introduce your code? Commented Dec 20, 2016 at 13:03

am = {{0, 1, 1, 1}, {0, 0, 1, 1}, {0, 0, 0, 1}, {0, 0, 0, 0}}
sa = SparseArray @ am;


Label matrix:

lm = RandomChoice[DictionaryLookup[x__ /; StringLength[x] == 3][[ ;; 100]], {4, 4}];


Construct edges annotated with labels using the matrices am and lm:

elist = Property[Rule @@ #, EdgeLabels -> lm[[## & @@ #]]] & /@ sa["NonzeroPositions"];


Use Graph3D

g1 = Graph3D[elist, EdgeLabelStyle -> 20, ImageSize -> 500]


If you wish you can use the vertex coordinates used by GraphPlot3D:

SetProperty[g1, VertexCoordinates -> GraphPlot3D[am][[1, 1, 1]]]


Alternatively, you can use GraphPlot3D with a custom EdgeRenderingFunction:

erf = {RGBColor[.5, 0, 0], Line[#], Text[lm[[## & @@ #2]], (#1[[1]] + #1[[2]])/2,
Background -> White]} &;

GraphPlot3D[am, EdgeRenderingFunction -> erf]