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

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
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

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

I'm not sure what it would mean to animate between graphs. Esp between ones that aren't isomorphic. You could, I suppose, take the position of each vertex in the graph and then interpolate between them in some way.

Do mean Graphs? Or do you mean plots, like "x-y" plots of some function?

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