4
$\begingroup$

Is there any way to make the edges of a GraphPlot black without tediously writing out a long "EdgeRenderingFunction"? I guess you could ask the same kind of question about vertex labeling.

For example, if I write EdgeRenderingFunction -> ({Black, Arrow[#1, 0.1]} &) I don't even get the standard directed edges, I get "arrows". How do I just turn the standard directed edges black (instead of the default red)?

$\endgroup$
5
$\begingroup$

Using Graph instead of GraphPlot you get many convenient options for styling as shown in @ubpdqn's answer.

If you have to use GraphPlot:

You can use the option PlotStyle->Black to get black edges.

To style the vertices you can post-process the output to change Text primitives into graphics primitives of your choice. For example:

el={1 -> 2, 2 -> 1, 3 -> 1, 3 -> 2, 4 -> 1, 4 -> 2,  4 -> 4};

g1 = GraphPlot[el, VertexLabeling -> True, PlotStyle -> Directive[Thick, Black]];
g2 = Block[{j = 1}, g1 /. Text[x_, y_] :> {ColorData[63, "ColorList"][[j++]], 
                           Disk[y, .2], Black, Style[Text[x[[1]], y], 20, Bold]}];

Row[{g1, g2}]

enter image description here

If the input graph does not have vertex labels:

el2 = RandomSample[{5 -> 1, 1 -> 2, 2 -> 1, 4 -> 1, 4 -> 2, 3 -> 1, 3 -> 2, 4 -> 4}];

g2a = GraphPlot[el2, ImageSize -> 350, PlotStyle -> Directive[Thick, Black]];
g2b = Block[{j = 1},  g2a /. Point[x_] :> 
     With[{k = j++}, {ColorData[63, "ColorList"][[k]], Disk[x, .21], 
       Black, Style[ Text[k, x], 20, Bold]}]];

Row[{g2a, g2b}]

enter image description here

However, using edge and vertex rendering functions is not much more tedious than the post-processing approach.

For example, changing Arrow to Line in your code gives black lines; and the VertexRenderingFunction you would need is very similar to the right-hand side of the replacement rule used above.

g3 = GraphPlot[el, EdgeRenderingFunction -> ({Thick,Black, Line[#1]} &)]

enter image description here

g4 = GraphPlot[el, EdgeRenderingFunction -> ({Thick, Black, Line[#1]} &),
  VertexRenderingFunction -> ({ColorData[63, "ColorList"][[#2]],
                               Disk[#, .1], Black, Text[#2, #1]} &)]

enter image description here

$\endgroup$
6
$\begingroup$

Graph (version 9) is very flexible:

For example:

enter image description here

Graph[{1 -> 2, 2 -> 3, 3 -> 1}, 
 EdgeStyle -> Directive[Thickness[0.02], Black], VertexSize -> 0.2, 
 VertexStyle -> Red]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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