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.

Minor aesthetic question here. I was playing around with Graph's and decided to render a cute-looking family of directed graphs, with the vertices being the number associated with the vertex. Here is an example with number of nodes $n=200$ (right-click and open in a new tab to see at proper resolution):

n = 200;
Graph[Table[i -> Mod[30 i, n, 1], {i, n}], ImageSize -> 1280, 
 VertexShape -> Table[i -> i, {i, n}], VertexSize -> 1, 
 VertexStyle -> White, EdgeStyle -> Green, Background -> Black]

enter image description here

It looks fine. Now let's try $n=5$:

n = 5;
Graph[Table[i -> Mod[30 i, n, 1], {i, n}], ImageSize -> 1280, 
 VertexShape -> Table[i -> i, {i, n}], VertexSize -> 1, 
 VertexStyle -> White, EdgeStyle -> Green, Background -> Black]

enter image description here

The vertex labels are gigantic and distort the figure to make it unreadable. Fine, let's just set VertexSize -> Automatic:

enter image description here

Much better. Let's try using VertexSize -> Automatic for the $n=200$ case once more:

enter image description here

The three-digit labels are unreadable, because Automatic does not appear to correctly scale them, and so it only displays the first digit and cuts off the rest with a ....

Is there an automatic way (other than VertexSize -> Automatic) to make text vertices show up as the right size without being truncated?

share|improve this question
    
Renders fine for me, 9.0.1, Windows, using VertexSize->Automatic –  rasher Jun 14 at 2:02

2 Answers 2

up vote 4 down vote accepted

I can see the same problem in Mathematica version 8.04. What cured the display problem was the explicit specification of a VertexShapeFunction as follows:

n = 200;
Graph[Table[i -> Mod[30 i, n, 1], {i, n}], ImageSize -> 1280, 
 VertexShape -> Table[i -> i, {i, n}], VertexSize -> Automatic, 
 VertexStyle -> White, EdgeStyle -> Green, Background -> Black, 
 VertexShapeFunction -> (Text[#2, #1] &)]

pic

You can add this last option for all Graphs instead of specifying it in every instance, by doing this:

SetOptions[Graph, VertexShapeFunction -> (Text[#2, #1] &)];

Then your original code with VertexSize -> Automatic should appear without the cut-off labels.

share|improve this answer
    
VertexShape->"Name" will work as well. The explicit Table specification is not necessary. –  Francois Vanderseypen yesterday
    
@FrancoisVanderseypen Thanks, you're right - I just copied that from the original question. –  Jens yesterday

You could play with GraphLayout:

n=200;
Graph[Table[i->Mod[30 i,n,1],{i,n}],ImageSize->1280,VertexShape->Table[i->i,    
  {i,n}],VertexSize->1,VertexStyle->White,EdgeStyle->Green,
  Background->Black,GraphLayout->"BalloonEmbedding"]

enter image description here

share|improve this answer
    
Hi, and thanks for the post. This doesn't exactly answer my question, since setting $n=5$ in your code still gives the same problem; I was mainly looking for something which renders correctly for all $n$. That said, my issue is a minor aesthetic one, and I can always do the vertex sizes manually if needed, so if no one else posts anything I'll accept this answer. I tend to use the SpringElectricalEmbedding method, I hadn't seen the BalloonEmbedding you used, seems like an interesting alternative. –  DumpsterDoofus Jun 14 at 3:29

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.