Last active
August 25, 2017 03:27
-
-
Save nicoguaro/3c6f759888be2b029c26 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division | |
from numpy import pi, sin, cos, mgrid | |
from scipy.special import jn, jn_zeros | |
from mpl_toolkits.mplot3d import Axes3D | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
from matplotlib import rcParams | |
# In Windows the next line should provide the full path to convert.exe | |
# since convert is a Windows command | |
rcParams['animation.convert_path'] = "C:\Program Files\ImageMagick-6.9.3\convert.exe" | |
rcParams['savefig.transparent'] = True | |
plot_args = {'rstride': 1, 'cstride': 1, 'cmap':"RdYlBu", | |
'linewidth': 0.2, 'antialiased': True, 'color': '#1e1e1e', | |
'shade': True, 'alpha': 1.0, 'vmin': -1, 'vmax':1} | |
def data_gen(num, m, n): | |
ax.cla() | |
lam = jn_zeros(m, n)[-1] | |
dt = 2*pi/(30*lam) | |
z = cos(m*t)*jn(m, lam*r)*sin(lam*num*dt) | |
surf = ax.plot_surface(x, y, z, **plot_args) | |
ax.view_init(elev=30, azim=45) | |
ax.set_xlim(-0.6, 0.6) | |
ax.set_ylim(-0.6, 0.6) | |
ax.set_zlim(-1, 1) | |
plt.axis("off") | |
return surf | |
r, t = mgrid[0:1:20j, 0:2*pi:40j] | |
x, y = r*cos(t), r*sin(t) | |
for m in range(0, 3): | |
for n in range(1, 4): | |
fig = plt.figure(dpi=600, facecolor=None) | |
ax = fig.add_subplot(111, projection='3d') | |
ani = animation.FuncAnimation(fig, data_gen, range(30), blit=False, | |
fargs=(m, n)) | |
# ani.save("Drum vibration mode01.gif", writer='imagemagick') | |
ani.save("Drum vibration mode%i%i.avi" % (m, n), writer='ffmpeg') | |
# plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from mpl_toolkits.mplot3d import Axes3D | |
import matplotlib.pyplot as plt | |
import matplotlib.animation as animation | |
# In Windows the next line should provide the full path to convert.exe | |
# since convert is a Windows command | |
#rcParams['animation.convert_path'] = "C:\Program Files\ImageMagick-6.9.3\convert.exe" | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
plot_args = {'rstride': 1, 'cstride': 1, 'cmap':"Spectral", | |
'linewidth': 0.1, 'antialiased': True, 'edgecolor': '#1e1e1e', | |
'shade': True, 'alpha': 1.0, 'vmin': -1, 'vmax':1} | |
x, y = np.mgrid[0:1:31j, 0:1:31j] | |
def data_gen(num): | |
ax.cla() | |
z = np.sin(3*np.pi*x)*np.sin(2*np.pi*y)*np.sin(0.1*np.pi*num) | |
surf = ax.plot_surface(x, y, z, **plot_args) | |
ax.view_init(elev=35, azim=45) | |
ax.set_xlim(0, 1) | |
ax.set_ylim(0, 1) | |
ax.set_zlim(-1, 1) | |
ax.set_xlabel(r"$x$") | |
ax.set_ylabel(r"$y$") | |
ax.set_zlabel(r"$z$") | |
ax.set_zticks([-1, -0.5, 0, 0.5, 1]) | |
return surf | |
ani = animation.FuncAnimation(fig, data_gen, range(30), blit=False) | |
ani.save("membrane-3-2.mp4") | |
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from matplotlib import rcParams | |
rcParams['font.family'] = 'serif' | |
rcParams['font.size'] = 16 | |
x = np.pi*np.linspace(-1, 1, 200) | |
y = np.sin(x) | |
plt.figure(figsize=(8,6)) | |
plt.plot(x/np.pi,np.pi*y) | |
plt.grid(True, color="blue", alpha=0.3) | |
plt.xlabel(r"$x/\pi$", size=18) | |
plt.ylabel(r"$\pi y$", size=18) | |
x = np.pi*np.linspace(-1, 1, 200) | |
y = np.pi*np.linspace(-1, 1, 200) | |
X,Y = np.meshgrid(x,y) | |
Z = np.sin(np.sqrt(X**2 + Y**2))/np.sqrt(X**2 + Y**2) | |
plt.figure(figsize=(8,8)) | |
plt.contourf(X,Y,Z, cmap="RdBu") | |
plt.xlabel(r"$x$", size=18) | |
plt.ylabel(r"$y$", size=18) | |
plt.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Animation of a rectangular membrane with initial conditions | |
0.02*(x - x**2)*(y - 2*y**2) | |
in the domain [0, 1] x [0, 0.5] | |
@author: Nicolas Guarin-Zapata | |
""" | |
from __future__ import division | |
from numpy import mgrid, sin, pi, sqrt, cos | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
import matplotlib.animation as animation | |
plot_args = {'rstride': 1, 'cstride': 1, 'cmap':"Spectral", | |
'linewidth': 0.1, 'antialiased': True, 'edgecolor': '#1e1e1e', | |
'shade': True, 'alpha': 1, 'vmin': -6e-4, 'vmax':6e-4} | |
def data_gen(num, Nx, Ny, dt): | |
ax.cla() | |
z = np.zeros_like(x) | |
t = num * dt | |
for m in range(1, Nx + 1, 2): | |
for n in range(1, Ny + 1, 2): | |
k = sqrt(m**2 + 4*n**2) | |
z += sin(m*pi*x) * sin(2*n*pi*y)*cos(20*pi*k*t)/(m*n)**3 | |
z = 0.64*z/pi**6 | |
surf = ax.plot_surface(x, y, z, **plot_args) | |
ax.set_zlim(-6e-4, 6e-4) | |
return surf | |
Nx = 50 | |
Ny = 50 | |
dt = 0.001 | |
y, x = mgrid[0:0.5:21j, 0:1:21j] | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
ani = animation.FuncAnimation(fig, data_gen, range(200), blit=False, | |
fargs=(Nx, Ny, dt)) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment