I have a graph that has nodes and (weighted, not directed, but this is not essential to be displayed) edges that is gradually built up in a procedural loop. How can I show this in an animation? Is there a way to make Animate[] use the looping parameter, which is also used to run the code to build the graph? Or is there some other way? I haven’t debugged my program yet, so I haven’t posted it here. I was also hoping to use the graphical animation to debug it.
You could use Monitor around whatever looping construct you’re using for your code.
As a quick example here I just delete one edge at a time from a complete graph and show each step:
g = CompleteGraph[8];
Monitor[
Do[
edge = EdgeList[g] // RandomChoice;
g = EdgeDelete[g, edge];
Pause[0.25];
,
16],
g]
Super helpful, thanks. However, still 2 issues
- When I use VertexAdd, I can’t just add a label for the vertex added. I have to add all of the labels, because it erases previous labels. Not a big deal
- Big deal: the display keeps jumping between different parts of the graph, switching their positions. I know it’s trying to optimize something visually, but it’s quite terrible. Is there a way to turn off the optimization.?I include a test file so you can see what I mean.
Also a third issue is I would like to have edge weights displayed proportional to line thickness (I have a matrix that keeps track of these weights, but I didn’t use it in the example above), but I don’t know how to do that.
Just an idea: start with the full final graph, but colored white, or very light. Then switch the colors on in succession.
That worked, thanks!
Keeping the previous format, is there anyway to have varying edge widths whenever I use EdgeAdd? I tried, but it doesn’t seem to work.
. I can get nodes to be different sizes, but not edges, probably misunderstanding the syntax.
Never mind, I figured out the syntax.