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.

enter image description here

For example, like above. I've read some examples and descriptions in here, but couldn't figured it out.

share|improve this question
    
Have you tried writing something down ? If so, please, share your code. –  Sektor Jul 6 at 19:48
    
Do you need the Combinatorica package? If not, just use EdgeStyle :) –  Öskå Jul 6 at 21:17
    
@Novice Looks like a PetersonGraph. Where did you get the image from? –  eldo Jul 6 at 21:48

3 Answers 3

Look up HighlightGraph.

HighlightGraph[
 CompleteGraph[5],
 EdgeList@CycleGraph[5]
]

(This solution is based on the accidental fact that CompleteGraph and CycleGraph name and connect the vertices in the same order, i.e. 1--2--3--4--5--1)

share|improve this answer
    
I would have written: "The solution is based on a thorough forensic inquiry on the accidental fact..." :) –  eldo Jul 6 at 22:56

I post this for illustrative purposes based on the title of the question (which is somewhat ambiguous). I agree as Szabolcs advice re: looking at documentation, which is good. Here are some motivating examples:

Your example: another way (exploiting Szabolcs observation):

cg = CompleteGraph[6];
el = EdgeList[cg]; 
path = EdgeList[CycleGraph[6]];
    Graph[EdgeList@cg, 
    EdgeStyle -> 
    Join[(# -> {Red, Thickness[0.01]} & /@ path), {Blue, 
    Thickness[0.01]}]]

enter image description here

or if you wanted different colors on the hightlighted path:

  Graph[EdgeList@cg,EdgeStyle -> 
    Join[MapThread[#1 -> {RGBColor[#2], Thickness[0.01]} &, {path, 
    RandomReal[{0, 1}, {6, 3}]}], {Blue, Thickness[0.01]}]]

![enter image description here][2]

A modification of the documentation to illustrate styles for HighlightGraph:

ged = GraphElementData["GraphHighlightStyle"]

=>:

{Automatic, "Dashed", "Dotted", "Thick", "VertexConcaveDiamond",
"VertexDiamond", "VertexTriangle", "DehighlightFade", 
"DehighlightGray", "DehighlightHide"}

An example (adapted from documentation):

Grid[Partition[
  Column /@ 
   Transpose[{Rest@ged, 
     HighlightGraph[
        cg, {1, 2 \[UndirectedEdge] 4, 3 \[UndirectedEdge] 6}, 
        GraphHighlightStyle -> #] & /@ Rest[ged]}], 3], Frame -> All]

enter image description here

Finally, you have a lot of control with wrapper Style or using EdgeStyle option of built in `Graph function:

Using Style

Graph[
      MapThread[Style[#1, RGBColor[#2], Thick] &,
      {el,RandomReal[{0, 1}, {Length@el, 3}]}]
       ]

enter image description here

Using EdgeStyle:

Graph[MapThread[
   Style[#1, RGBColor[#2], Thick] &, {el, 
    RandomReal[{0, 1}, {Length@el, 3}]}]]]
Graph[el, 
 EdgeStyle -> 
  MapThread[#1 -> {RGBColor[#2], Thick} &, {el, 
    RandomReal[{0, 1}, {Length@el, 3}]}]]

enter image description here

share|improve this answer

It looks like you want to make an edge rendering function: http://reference.wolfram.com/mathematica/ref/EdgeRenderingFunction.html

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.