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

The Archive Base Latest Questions

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

I have some issues with the FuncAnimation fonction of MatPlotLib . I can’t configure

  • 0

I have some issues with the FuncAnimation fonction of MatPlotLib. I can’t configure it to my code… I hope someone could help me !!

This is a diffusion equation, I need to plot it for each step of the time. At each step, the result of the calculation is a numpy array. I manage to plot it in a dynamic way with pyplot.interactive(True) but it is very laggy. I read that FuncAnimation can deal with that problem but I did not manage to have it working with results in lists or arrays.

Here is the code with a classic slow plot :
It produces a vector of vectors (U) wich are ploted after all calculations

import numpy as np
import scipy
from scipy.linalg import solve_banded
from matplotlib import pyplot as plt
import matplotlib.animation as animation


def DrawRecord(U):
    plt.interactive(True)
    plt.figure(1)
    for i in range(0,len(U)):
        plt.clf()
        plt.plot(U[i])
        plt.ylim([0,1])
        plt.draw()

J=350.0 
dt=0.01 
T=3.0 
t=np.arange(dt,T,dt) 
dx=1.0/J 

D=0.005 
c=0.5 
r=0.1 

mu=c*dt/(2.0*dx) 
lambd=D*dt/(dx**2.0) 

K_x=50.0*np.ones(J-1) 
alpha_t=0.5*np.ones(len(t)) 

#initial conditions
u=np.zeros(J) 
u[J/5*1:J/5*2]=1 
U=u

espace=np.linspace(0,1,J) 

#Matrix
A=np.diag(-lambd*np.ones(J-2),1)+np.diag((1+2*lambd)*np.ones(J-1),0)+np.diag(-lambd*np.ones(J-2),-1)  
AA=scipy.linalg.inv(A)


for i in t:

    u[1:J]=scipy.dot(AA,u[1:J]+(r-alpha_t[i/dt])*dt*(u[1:J]-u[1:J]/K_x))
    u[0]=0 
    u[J-1]=0  

    U=np.vstack([U,u])

DrawRecord(U)

And here is my try of making turn the FuncAnimation with the previous code (big fail) :
nb : U contents the arrays of results calculated for each steps

global U

fig = plt.figure()
window = fig.add_subplot(111)
line, = window.plot(list(U[1,:]))

def init():
    line=list(U[1,:])
    return line

def animate(i):
    line.set_ydata(list(U[i,:]))
    return line

anim = animation.FuncAnimation(fig, animate, init_func=init,
                           frames=200, interval=20, blit=True)

plt.show()

That produces a lot of errors … Maybe someone can set it up for the previous code !
I hope I’m clear (sorry for my english) and thank you for your help.

  • 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:55:54+00:00Added an answer on June 15, 2026 at 1:55 am

    Your init function isn’t right, it should be:

    def init():
        line.set_ydata(U[1,:])
        return line
    

    You also don’t need to convert the numpy slice to a list.

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

Sidebar

Related Questions

I am using Symfony 1.2 and I have some issues switching context. This code
I have some issues with .load : My site use this line of code
I have some issues with using databinding in silverlight 4 xaml pages, this is
I'm using jQuery UI Select Menu and occasionally have some issues. This is located
I have some issues with this: First I create my object and move it
In my Universal-App i have some issues where the app crashes. I could not
I have been making some progress on this but still have some issues to
Where can I get the sources for these 2 assemblies? I have some issues
I have some issues in setting the classpath for the a project for which
I have some issues with a PHP file that is not working properly. The

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.