Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8902809
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:42:26+00:00 2026-06-15T01:42:26+00:00

I would like to animate a graph that grows over time. This is what

  • 0

I would like to animate a graph that grows over time.

This is what I have so far:

fig = plt.figure()
ims = []
graph = nx.Graph()
for i in range(50):
    // Code to modify Graph
    nx.draw(graph, pos=nx.get_node_attributes(graph,'Position'))
    im = plt.draw()
    self.ims.append([im])
ani = animation.ArtistAnimation(fig, ims, interval=50, blit=True,repeat_delay=1000)
ani.save('dynamic_images.mp4')
plt.show()

However, I get the following error message:

 File "main.py", line 204, in <module>
    repeat_delay=1000)
  File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 356, in __init__
    TimedAnimation.__init__(self, fig, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 304, in __init__
    Animation.__init__(self, fig, event_source=event_source, *args, **kwargs)
  File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 53, in __init__
    self._init_draw()
  File "/usr/lib/pymodules/python2.7/matplotlib/animation.py", line 363, in _init_draw
    artist.set_visible(False)
AttributeError: 'NoneType' object has no attribute 'set_visible'
nicomoto@nicomoto-VirtualBox:~/Desktop/CS8903-SpecialProblem/Code/

What I want is an animation, where you can see the graph growing. I can save the graph at each stage, and might be able to create an animation outside matplotlib, but is there any way of getting it work like this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:42:27+00:00Added an answer on June 15, 2026 at 1:42 am

    Upon review, that code wasn’t nearly as relevant to this problem as I’d thought. However, I was able to use this SO answer and this SO answer to cobble together an answer for you. Here’s code that will create a graph, add 50 random nodes and 50 random edges to it, and display an image of the graph after every node and edge is added. A few of the key changes from your code:

    1. This code is based on using pylab.ion() (see here for more info).
    2. Your code tries to use one figure and change the image within it. This code creates a new figure for each frame.
    3. This code doesn’t write out to .mp4. If you really need to do that, I would suggest writing the figures out to .png file while rendering them, and converting to mp4 after the fact.
    4. Note that this code uses matplotlib.pyplot.pause() instead of time.sleep(). The figures won’t render if you use time.sleep().

    Good luck!

    import random
    import pylab
    from matplotlib.pyplot import pause
    import networkx as nx
    pylab.ion()
    
    graph = nx.Graph()
    node_number = 0
    graph.add_node(node_number, Position=(random.randrange(0, 100), random.randrange(0, 100)))
    
    def get_fig():
        global node_number
        node_number += 1
        graph.add_node(node_number, Position=(random.randrange(0, 100), random.randrange(0, 100)))
        graph.add_edge(node_number, random.choice(graph.nodes()))
        fig = pylab.figure()
        nx.draw(graph, pos=nx.get_node_attributes(graph,'Position'))
        return fig
    
    num_plots = 50;
    pylab.show()
    
    for i in range(num_plots):
    
        fig = get_fig()
        fig.canvas.draw()
        pylab.draw()
        pause(2)
        pylab.close(fig)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really large PNG file that I would like to animate over
I have a UIView that I would like to animate a flip up. This
I have an NSArray of strings that I would like to animate with a
I have a UIView that I would like to animate into the screen in
I have this jquery plugin that zooms in on photos, but I would like
I would like to animate nsmenuitem that I have for my app (preferably use
I would like to animate things in 3D space. I know this is possible
I have two views, jumpBarPortrait and jumpBarLandscape I would like to animate between the
I am creating an application that uses popups. However, I would like to animate
I would like to animate a UI control (an Image actually) over a Path

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.