For those who are having trouble viewing these examples, they can all be found in a repository here.
If you are using windows, insert the following lines at the top of your script
import subprocess
subprocess.call('dir', shell=true)
Sine Wave
The example shows how to make a simple animated sine wave using the code provided below.
import pyvie as pv
import numpy as np
import matplotlib.pyplot as plt
movie = pv.Movie('SineWaveExample',framerate=20,file_type='.png',movie_type = '.avi')
plt.figure(figsize = (10,10))
for phi in np.linspace(0,2*np.pi,300):
plt.clf()
x = np.linspace(0,2*np.pi,100)
y = np.sin(x+phi)
plt.plot(x,y,linewidth = 4)
plt.xlim(0,2*np.pi)
plt.grid(alpha=.5)
plt.title('Sine Wave Example',fontsize = 22)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
movie.gather()
movie.finalize()
Updating Plot
The example shows how to make an updating plot using the code provided below.
import pyvie as pv
import numpy as np
import matplotlib.pyplot as plt
movie = pv.Movie('UpdatingPlotExample',framerate=10,file_type='.png',movie_type = '.avi')
plt.figure(figsize = (10,10))
x_data = []
y_data = []
lower_line = []
upper_line = []
for t in range(101):
plt.clf()
y_data.append(t*np.random.choice([1,2,3]))
x_data.append(t)
lower_line.append(t)
upper_line.append(3*t)
plt.plot(x_data,lower_line,linewidth=2,c='r')
plt.plot(x_data,upper_line,linewidth=2,c='g')
plt.plot(x_data,y_data,linewidth=2,c='black')
plt.fill_between(x_data,lower_line,upper_line,alpha = .3,color='black')
plt.xlim(0,100)
plt.ylim(0,300)
plt.title('Updating Plot',fontsize = 22)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
plt.grid(alpha=.5)
movie.gather()
movie.finalize()
Imshow
The example shows how to make a movie using imshow using the code provided below.
import pyvie as pv
import numpy as np
import matplotlib.pyplot as plt
movie = pv.Movie("ImshowExample",framerate=5,file_type='.png',movie_type = '.avi')
plt.figure(figsize=(10,10))
grid = np.zeros((10,10))
for t in range(100):
plt.clf()
y = np.random.randint(0,grid.shape[0])
x = np.random.randint(0,grid.shape[1])
grid[y,x] += 1
plt.imshow(grid)
plt.title('2D Imshow',fontsize = 22)
plt.xticks(fontsize = 15)
plt.yticks(fontsize = 15)
movie.gather()
movie.finalize()
Subplots
The example shows how to make a movie of a skydiver simulation using the code provided below.
import matplotlib.pyplot as plt
import numpy as np
import pyvie as pv
movie = pv.Movie("Skydiver",framerate=10,file_type='.png',movie_type = '.avi')
x0 = 0
y0 = 1000
x = [x0]
y = [y0]
vix = 10
viy = 0
vx = [vix]
vy = [viy]
axi = 0
ayi = -9.81
ax = [axi]
ay = [ayi]
start = 0
end = 15
steps = 20
time = np.linspace(start,end,steps)
for t in time[1:]:
f, ((ax1, ax2),(ax3, ax4)) = plt.subplots(2, 2, figsize=(10,10))
ax1.set_title('SkydiverExample',fontsize=22)
ax1.scatter(x[-1], y[-1])
ax1.set_ylim(0,1050)
ax1.set_xlim(-5,155)
ax1.tick_params(labelsize=15)
ax2.set_title('Skydiver Trajectory',fontsize=22)
ax2.plot(x, y)
ax2.set_ylim(0,1050)
ax2.set_xlim(-5,155)
ax2.tick_params(labelsize=15)
ax3.set_title('Skydiver Velocity',fontsize=22)
ax3.plot(time[0:len(vx)],np.sqrt(np.array(vx)**2+np.array(vy)**2))
ax3.set_ylim(0,145)
ax3.set_xlim(-1,15)
ax3.tick_params(labelsize=15)
ax4.set_title('Skydiver Acceleration',fontsize=22)
ax4.plot(time[0:len(ax)],np.sqrt(np.array(ax)**2+np.array(ay)**2))
ax4.set_xlim(-1,15)
ax4.tick_params(labelsize=15)
movie.gather()
f.clf()
x.append(.5*ax[-1]*t**2 + vix*t + x0)
y.append(.5*ay[-1]*t**2 + viy*t + y0)
vx.append(vix + ax[-1]*t)
vy.append(viy + ay[-1]*t)
ax.append(axi)
ay.append(ayi)
movie.finalize()