6
$\begingroup$

Consider the graph produced by:

M = {{0, 0, 1, 0}, {1, 0, 0, 1}, {1, 1, 0, 0}, {0, 1, 0, 0}};
GraphPlot[M, DirectedEdges -> True, 
 VertexRenderingFunction -> ({EdgeForm[Black], LightRed, 
     Disk[#1, {.7, .1}], Black, Text[Subscript["C", #2], #1]} &)]

Output

Is it possible to tweak the layout so that more room is left around the vertices for use by the VertexRenderingFunction? (I want to be able to put more text in each of the labels.)

$\endgroup$
7
$\begingroup$

Generally I'd recommend using Graph instead of GraphPlot. One way to solve your specific problem is to affect VertexCoordinates to scale your graph:

M = {{0, 0, 1, 0}, {1, 0, 0, 1}, {1, 1, 0, 0}, {0, 1, 0, 0}};
Manipulate[ AdjacencyGraph[M, DirectedEdges -> True, VertexShapeFunction -> 
({EdgeForm[Black], LightRed, Disk[#1, {.7, .1}], Black, 
Text[Subscript["C", #2], #1]} &),  VertexCoordinates -> scale   
AbsoluteOptions[AdjacencyGraph[M], VertexCoordinates][[2]]], {{scale, 2}, .1, 3}]

enter image description here

$\endgroup$
  • $\begingroup$ Much cleaner, thanks! I had to dig a bit to figure out what scale was multiplying, but it was worth it! $\endgroup$ – Kaelin Colclasure May 2 '12 at 0:51
  • $\begingroup$ The arrows between nodes C2 and C4 are reversed ... is this a bug in the graph layout? $\endgroup$ – StackExchanger May 6 '12 at 5:41
3
$\begingroup$

How about changing the AspectRatio?

M = {{0, 0, 1, 0}, {1, 0, 0, 1}, {1, 1, 0, 0}, {0, 1, 0, 0}};
GraphPlot[M, DirectedEdges -> True, 
 VertexRenderingFunction -> ({EdgeForm[Black], LightRed, 
     Disk[#1, {.4, .1}], Black, Text[Subscript["C", #2], #1]} &), 
 AspectRatio -> 0.2]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Hmm, AspectRatio was the first option I tried, but my Mathematica (8.0.4 on Mac OS X) does not render it like you've shown here. Instead I just get a flatter version of the first diagram, with the ovals still overlapping. $\endgroup$ – Kaelin Colclasure May 2 '12 at 0:26
  • $\begingroup$ yuck. The arrows coalesce to form a skewed 6pt star! $\endgroup$ – rm -rf May 2 '12 at 0:35
1
$\begingroup$

This does the job in a rather brute-force manner:

stretch = {1.5, 1};
GraphPlot[M, 
 EdgeRenderingFunction -> ({Black, Line[Map[#*stretch &, #1]]} &), 
 VertexRenderingFunction -> ({EdgeForm[Black], LightRed, 
     Disk[#1*stretch, {.5, .1}], Black, 
     Text[Subscript["C", #2], #1*stretch]} &)]

Output

The downside is you have to do both edge and vertex rendering. I'll leave this question open, hoping someone has a better solution.

$\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.