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 9173231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:32:29+00:00 2026-06-17T16:32:29+00:00

This is my script so far: import numpy as np import matplotlib.pyplot as plt

  • 0

This is my script so far:

import numpy as np
import matplotlib.pyplot as plt
import random
t=0
r=3.0
n=0
A=[]
for x in range(10):
  for y in range(10):
    A.append([random.uniform(0,1),random.uniform(0,1)])
for m in range(len(A)):
  plt.plot(A[m][0],A[m][1], "x", color="blue")
plt.show()
while n<=100:
  for m in range(len(A)):
    A[m][0]=r*A[m][0]*(1-A[m][0])
    A[m][1]=r*A[m][1]*(1-A[m][1])
  for m in range(len(A)):
    plt.plot(A[m][0],A[m][1], "x", color="blue")
  plt.show()
  n+=1

What I want to do now is animate it, so that I don’t have to close the plot each time it for python to recalculate an show me the next image. Instead, it should show me a new plot every say 5s. What’s the best way for me to do that?

  • 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-17T16:32:30+00:00Added an answer on June 17, 2026 at 4:32 pm

    Use plt.ion() to enable interactive plotting (doesn’t make the execution stop when a plot-window is opened) and then use plt.clf() to clear the plot.

    A working sample is:

    import numpy as np
    import matplotlib.pyplot as plt
    plt.ion()
    
    import random
    t=0
    r=3.0
    n=0
    A=[]
    for x in range(10):
        for y in range(10):
            A.append([random.uniform(0,1),random.uniform(0,1)])
    
    for m in range(len(A)):
        plt.plot(A[m][0],A[m][1], "x", color="blue")
        plt.draw()
    plt.pause(1)
    
    while n<=100:
        for m in range(len(A)):
            A[m][0]=r*A[m][0]*(1-A[m][0])
            A[m][1]=r*A[m][1]*(1-A[m][1])
        for m in range(len(A)):
            plt.plot(A[m][0],A[m][1], "x", color="blue")
        plt.draw()
        plt.pause(1)
        plt.clf()
    

    You must use plt.draw() to force the GUI to update immediately and plt.pause(t) to break for t seconds. Actually, I’m not quite sure how you want to treat the two parts of your script (the two loops containing plot-commands) in terms of animation, but hopefully, my code will guide you the right way.

    Remarks

    First, I’d recommend to stick to some conventions when coding python. Use 4-space indentation, this makes your code much more readable. Second, I’d recommend using numpy for arrays. You import it but you don’t use it. This makes your code definitely faster.
    Third and last, are you aware of the signature plot(x,y,"bx") for matplotlib? I think it’s really convenient.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is what I have so far - my dropbox public URL creation script
this is what I have so far: <script> $(document).ready(function(){ $(.entry-content img:first).addClass('postimage'); }); </script> As
SO this is my code so far: JS: <script type=text/javascript> function Hide(srcField) { var
Receiving a segfault when running this very short script in Ubuntu. from osgeo import
So far my code is this : from glob import glob shakedir='D:\report\shakeall' from shakedir
This python script is the best I have come up with so far. I
I want to plot (i.e. write a file) with matplotlib from a script that
This script saves the files as /home/name/main/all my files and stuff . I want
This script cannot find bannersize unless I write <div id=bannersize></div> before the javascript. The
This script works fine on single click but on double click it shows both

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.