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:
However:
CompleteGraph[4,
EdgeWeight -> Range@6,
VertexShapeFunction -> "Name",
EdgeLabels -> "EdgeWeight"]
Results in:
So, no Edge Labels ... I guess it is a bug.
I used a nasty construct like:
adj = {{\[Infinity], 1, 1, 1, 1}, {1, \[Infinity], 2, 2, 2},
{1, 2, \[Infinity], 2, 2}, {1, 2, 2, \[Infinity], 2},
{1, 2, 2, 2, \[Infinity]}};
WeightedAdjacencyGraph[adj,
VertexShapeFunction -> "Name",
EdgeLabels ->
MapThread[Rule,{EdgeList@#,AbsoluteOptions[#, EdgeWeight]/.{_ -> x_}-> x}],
GraphHighlight -> FindEdgeCover[#]]
&@ WeightedAdjacencyGraph[adj]
Better ideas?
EdgeLabels
works fine.EdgeWeights
does not.It may already be obvious from Belisarius' second example that the problem lies with
EdgeWeights
notEdgeLabels
Here's some additional evidence.
EdgeLabels
very gladly displays a variety of labels correctly. But when you ask mma to display"EdgeWeights"
, it incorrectly displays 1's, no matter what you've stored there.The bug is not unique to
CompleteGraph
.Graph
andGridGraph
have the same problem.For a regular
GraphPlot
, you will need a slightly more complicated solution usingEdgeRenderingFunction
(documentation). Suppose you have an adjacency matrix where the elements are also the (directional) weights.Here are some labels for the vertices, supposing you are drawing network diagrams for international inter-bank exposures (the original has a lot more countries!).
The following does what you need. The tricks are the reference back to the adjacency matrix using the parts of
#2
inside the part specification, to reference the correct elements ofnums
, and theMean[#1]
to locate the label at the midpoint of the edge. The slot#1
seems to hold the coordinates of the vertices.The solution is easy. Upgrade to V 8.0.1 :)
At least that is what I have and it works there. (windows 7)
Btw, I do not know if the labels on the edges are correct, but at least it does put them on the figure, unlike your image).
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: