Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

animate time series python

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation

dt = 0.01
tfinal = 1
x0 = 0

sqrtdt = np.sqrt(dt)
n = int(tfinal/dt)
xtraj = np.zeros(n+1, float)
trange = np.linspace(start=0,stop=tfinal ,num=n+1)
xtraj[0] = x0

for i in range(n):
    xtraj[i+1] = xtraj[i] + np.random.normal()

x = trange
y = xtraj

# animation line plot example

fig, ax = plt.subplots(1, 1, figsize = (6, 6))

def animate(i):
    ax.cla() # clear the previous image
    ax.plot(x[:i], y[:i]) # plot the line
    ax.set_xlim([x0, tfinal]) # fix the x axis
    ax.set_ylim([1.1*np.min(y), 1.1*np.max(y)]) # fix the y axis

anim = animation.FuncAnimation(fig, animate, frames = len(x) + 1, interval = 1, blit = False)
plt.show()
Comment

animate time series python


import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation

dt = 0.01
tfinal = 1
x0 = 0

sqrtdt = np.sqrt(dt)
n = int(tfinal/dt)
xtraj = np.zeros(n+1, float)
trange = np.linspace(start=0,stop=tfinal ,num=n+1)
xtraj[0] = x0

for i in range(n):
    xtraj[i+1] = xtraj[i] + np.random.normal()

x = trange
y = xtraj

# animation line plot example

fig, ax = plt.subplots(1, 1, figsize = (6, 6))

def animate(i):
    ax.cla() # clear the previous image
    ax.plot(x[:i], y[:i]) # plot the line
    ax.set_xlim([x0, tfinal]) # fix the x axis
    ax.set_ylim([1.1*np.min(y), 1.1*np.max(y)]) # fix the y axis

anim = animation.FuncAnimation(fig, animate, frames = len(x) + 1, interval = 1, blit = False)
plt.show()

Comment

PREVIOUS NEXT
Code Example
Python :: emacs region indent python 
Python :: how to pipe using sybprosses run python 
Python :: polynomial features random forest classifier 
Python :: how to add card in py-trello 
Python :: exact distance 
Python :: python check string float 
Python :: list to string python 
Python :: how to clear screen python 
Python :: how to add headers in csv file using python 
Python :: how to visualize decision tree in python 
Python :: import data in pandad 
Python :: adaptive thresholding cv2 python 
Python :: django read mesage 
Python :: gow to find a letter in a word in python 
Python :: how to change number of steps in tensorflow object detection api 
Python :: np zeros in more dimensions 
Python :: exclude columns in df 
Python :: previous value list loop python 
Python :: how to add a number to a variable in django template 
Python :: raw string 
Python :: Test Speed internet using Python 
Python :: how to print dataframe in python without index 
Python :: remove characters in array of string python 
Python :: plt change legend coordinates 
Python :: python create random matrix 
Python :: select columns from dataframe pandas 
Python :: cosine similarity python numpy 
Python :: convert base64 to image python 
Python :: how to check if two columns match in pandas 
Python :: vscode not recognizing python import 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =