0
$\begingroup$

I often find myself manually trying different graph layouts (Radial Drawing, Layered Drawing, etc ...) to find the best possible visualization for graphs. Is there a quick command to display ALL graph layouts at once? So that I can pick the best configuration.

$\endgroup$
7
  • 1
    $\begingroup$ You can write a function that does this once, then keep using it as you need it $\endgroup$
    – Szabolcs
    Commented Jun 16, 2021 at 17:37
  • $\begingroup$ Given how ubiquitous and useful this problem can be, I am asking whether there is a quick way of doing this generation. A Table where I copy paste all the layouts is a possibility, but very likely not the most efficient way. $\endgroup$
    – anon248
    Commented Jun 16, 2021 at 17:52
  • 2
    $\begingroup$ maybe something like embeddings = {"BalloonEmbedding", "CircularEmbedding", "GridEmbedding", "LayeredEmbedding", "LayeredDigraphEmbedding", "RadialEmbedding", "SpectralEmbedding", "SpringEmbedding"}; layoutButtons[g_Graph] := Grid@Partition[ Button[Panel@ Tooltip[Thumbnail[Rasterize@Graph[EdgeList@g, GraphLayout -> #], Tiny], #], CopyToClipboard[Defer[GraphLayout -> #]], Method -> "Queued"] & /@ embeddings, 4]; layoutButtons[graph]? $\endgroup$
    – kglr
    Commented Jun 16, 2021 at 18:38
  • $\begingroup$ you can also select from a limited set of choices available under GraphLayout from the right-click context menu. (It should be possible to modify this list to add more embeddings and tooltip previews). $\endgroup$
    – kglr
    Commented Jun 16, 2021 at 18:44
  • $\begingroup$ @kglr This is perfect, thanks. The only thing I changed (is Tiny to Large) in case others want a bigger visualization. The list can also be made larger like you said. $\endgroup$
    – anon248
    Commented Jun 16, 2021 at 19:23

1 Answer 1

1
$\begingroup$

This answer was provided by kglr (Minor edits from me):

embeddings = {"BalloonEmbedding", "CircularEmbedding", 
  "GridEmbedding", "LayeredEmbedding", "LayeredDigraphEmbedding", 
  "RadialEmbedding", "SpectralEmbedding", "SpringEmbedding", 
  "BipartiteEmbedding", "TutteEmbedding", "StarEmbedding", 
  "TutteEmbedding", "SpringElectricalEmbedding", "GravityEmbedding", 
  "MultipartiteEmbedding", "LinearEmbedding", 
  "CircularMultipartiteEmbedding", "DiscreteSpiralEmbedding"}; 
layoutButtons[g_Graph] := 
 Grid@Partition[
   Button[Panel@
       Tooltip[Thumbnail[
         Rasterize@Graph[EdgeList@g, GraphLayout -> #], Large], #], 
      CopyToClipboard[Defer[GraphLayout -> #]], 
      Method -> "Queued"] & /@ embeddings, 4];

Function use:

layoutButtons[graph]

where graph is the object you are trying to visualize.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.