3
$\begingroup$

For the artistic,the graph layout could be more important sometimes.So I must to put a bad sentence to describe the clumsy GraphLayout of Mathematica but my poor vocabulary.My target is:

enter image description here

This is my code

    g = Graph[{1, 7, 6, 2, 3, 4, 5}, {1 <-> 2, 1 <-> 3, 1 <-> 7, 7 <-> 6, 
   7 <-> 3, 6 <-> 4, 6 <-> 5, 2 <-> 3, 3 <-> 4, 4 <-> 5}, 
  VertexSize -> Large, 
  GraphLayout -> {"MultipartiteEmbedding", 
    "VertexPartition" -> {3, 4}}, 
  EdgeStyle -> Directive[Thick, Black], 
  VertexShape -> Graphics[{Thick, Circle[]}], 
  VertexLabels -> Placed["Name", Center]]

enter image description here

I know the VertexCoordinates can achieve me.But write so much coordinates isn't a sensible option.

If I use a Rotate like following,then the label is followed.

Rotate[g, 3 Pi/2]

enter image description here

$\endgroup$
4
$\begingroup$
g2 = SetProperty[g, VertexCoordinates -> RotationTransform[3 Pi/2] @ GraphEmbedding[g]]

Mathematica graphics

Alternatively, you can use

g2 = SetProperty[g, VertexCoordinates -> (RotationMatrix[3 Pi/2].# & /@ 
         GraphEmbedding[g])]

same picture

SetProperty[g, VertexCoordinates -> (ScalingMatrix[1/5, {1, 0}].# & /@ 
       RotationMatrix[3 Pi/2].# & /@ GraphEmbedding[g])]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Ok.I have to Rotate it in the last.But this is a not bad solution.Thanks a lot. $\endgroup$ – yode Mar 18 '16 at 2:10
  • $\begingroup$ Another qeustion that can I make 1,7,6 be more near to 2,3,4,5? $\endgroup$ – yode Mar 18 '16 at 2:12
  • $\begingroup$ @yode, thank you for the accept. Re your second question, perhaps VertexCoordinates -> ((RotationMatrix[3 Pi/2].# & /@ GraphEmbedding[g]) /. -1. -> -.25)? $\endgroup$ – kglr Mar 18 '16 at 9:41
  • $\begingroup$ Thanks for your promption.Maybe there is a better solution derive from you.SetProperty[g,VertexCoordinates->ScalingTransform[0.3,{0,1}]@*RotationTransform[3 Pi/2]@GraphEmbedding[g]] $\endgroup$ – yode Mar 18 '16 at 9:49
  • $\begingroup$ @yode I agree that's much better. $\endgroup$ – kglr Mar 18 '16 at 10:49

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.