Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'm working on a program that finds special [called "interval"] edge-colorings for graphs. Output is as follows:

Coloring = {1 \[UndirectedEdge] 10 -> 1, 1 \[UndirectedEdge] 2 -> 2,  
            9 \[UndirectedEdge] 10 -> 2, 1 \[UndirectedEdge] 9 -> 3,  
            2 \[UndirectedEdge] 10 -> 3, 1 \[UndirectedEdge] 3 -> 4}

Now I want to visualize the coloring. I use EdgeLabels->Coloring, but it writes the labels in the middle, which is not comfortable, especially in case of symmetric graphs like Complete Graphs. I want to display 2 labels on both ends of each edge.

Right now I can display it only on one end of each edge using the following code:

1 \[UndirectedEdge] 10 -> Placed[1, 1/6]

and I get the following result:

CompleteGraph[10]

Documentation suggests to use Placed[{1,1},{"Start","End"}] to display 2 labels on two ends. That particular example works, but when I change "Start" or "End" to 1/6 or 5/6, no labels are displayed at all.

share|improve this question

2 Answers 2

up vote 6 down vote accepted

You may:

Show@Table[
  CompleteGraph[3, 
   EdgeLabels -> {1 \[UndirectedEdge] 3 -> Placed[1, p]}, 
   ImagePadding -> 10], {p, {1/6, 1/2, 5/6}}]

enter image description here

share|improve this answer
    
didn't know Show@Table syntax :) –  Hrant Khachatrian Apr 28 '12 at 20:56
3  
@HrantKhachatrian Please be aware that you are building your Graph 3 times. Not a big deal for simple cases, but could be a burden if your Graph is time consuming to build up –  belisarius Apr 28 '12 at 21:00
    
Yes, I guessed that. Thank you. In fact constructing the coloring takes much-much more time than drawing the graph, so it's not a problem at all. –  Hrant Khachatrian Apr 28 '12 at 22:06

Using GraphPlot and a custom EdgeRenderingFunction

   ClearAll[erf];
   erf[pos_List, lblcolors_, fontsizes_, linecolor_: Blue] := 
   {linecolor, Line[#], 
   Sequence @@ Table[
   Inset[Style[Text[#3], lblcolors[[i]], FontSize -> fontsizes[[i]]], 
   pos[[i]] First@# + (1 - pos[[i]]) Last@#, Automatic, Automatic, #[[2]] - #[[1]],
   Background -> White], {i, 1, Length@pos}]} &

example data

   edges = {{4 -> 2}, {5 -> 1}, {3 -> 2}, {2 -> 5}, {3 -> 5}};
   labelededges = MapIndexed[{First@#1, ToString@First@#2} &, edges];

Usage:

   GraphPlot[labelededges, 
   EdgeRenderingFunction -> erf[{(5/6), 1/6}, {Green, Red}, {16, 24}],
   PlotStyle -> Thick, VertexLabeling -> True, ImagePadding -> 20]

Output:

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.