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.

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.)

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

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

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

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.

share|improve this answer
add comment

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

share|improve this answer
    
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. –  Kaelin Colclasure May 2 '12 at 0:26
    
yuck. The arrows coalesce to form a skewed 6pt star! –  rm -rf May 2 '12 at 0:35
add comment

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.