4
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ Renders fine for me, 9.0.1, Windows, using VertexSize->Automatic $\endgroup$ – ciao Jun 14 '14 at 2:02
  • $\begingroup$ I would need of this software to generate such random numbers on each vertice. Please , what is the name of software? $\endgroup$ – user42779 Sep 1 '16 at 19:35
  • $\begingroup$ If you have a new question, please ask it by clicking the Ask Question button. Include a link to this question if it helps provide context. - From Review $\endgroup$ – bbgodfrey Sep 1 '16 at 20:15
  • $\begingroup$ This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review $\endgroup$ – Feyre Sep 1 '16 at 21:41
5
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ VertexShape->"Name" will work as well. The explicit Table specification is not necessary. $\endgroup$ – Francois Vanderseypen Aug 19 '14 at 5:03
  • $\begingroup$ @FrancoisVanderseypen Thanks, you're right - I just copied that from the original question. $\endgroup$ – Jens Aug 19 '14 at 5:08
2
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – DumpsterDoofus Jun 14 '14 at 3:29

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.