Group Abstract Group Abstract

Message Boards Message Boards

Is it possible to animate RandomGraph?

Posted 10 years ago

Would it be possible to animate between graph layouts or two random graphs? Thanks in advance.

POSTED BY: Matthew Luther
5 Replies
Posted 10 years ago

Wow! I have much to learn about Mathematica and I truly appreciate your time and consideration. Thank you both.

POSTED BY: Matthew Luther

There isn't built-in functionality for this.

To do this, you would need to find the location of the vertices in both layouts and and interpolate between them.

Suppose you have two graphs:

old = Graph[EdgeList@PetersenGraph[5, 2], 
  GraphLayout -> "SpringEmbedding"]
new = Graph[EdgeList@PetersenGraph[5, 2], 
  GraphLayout -> "BalloonEmbedding"]

We can get the locations of the vertices:

oldVertexCoors = 
  VertexCoordinates /. AbsoluteOptions[old, VertexCoordinates];

newVertexCoors = 
  VertexCoordinates /. AbsoluteOptions[new, VertexCoordinates];

And then make a Manipulate that interpolates between these:

Manipulate[
 Graph[EdgeList@PetersenGraph[5, 2], 
  VertexCoordinates -> (oldVertexCoors + (newVertexCoors - 
        oldVertexCoors) t)], {t, 0, 1}]
POSTED BY: Sean Clarke

Very nice, @Sean! There is simpler GraphEmbedding:

oldVertexCoors=GraphEmbedding[old];
newVertexCoors=GraphEmbedding[new];

And it probably worth fixing image size:

Manipulate[Graph[
  EdgeList@PetersenGraph[5, 2], 
  VertexCoordinates -> (oldVertexCoors + (newVertexCoors - 
        oldVertexCoors) t), ImageSize -> {300, 300}], {t, 0, 1}]

enter image description here

POSTED BY: Vitaliy Kaurov
Posted 10 years ago

I would like to interpolate (opposed to snapping) between these randomized layouts: Demo 1: http://demonstrations.wolfram.com/TheRayPuzzle/ Demo 2: http://demonstrations.wolfram.com/AutomatedGraphLayout/

The layouts are being hard reset, I am wondering if there is a simple way to transition between them. Or if you know a technique that might suffice for this type of visualization.

Thanks for this reply, I appreciate it.

POSTED BY: Matthew Luther
POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard