Last active
December 1, 2018 14:18
-
-
Save sabopy/f5a9f3979133fd95efee7ea781158eff to your computer and use it in GitHub Desktop.
正規分布の標準偏差変化アニメーション
This file contains 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 | |
import matplotlib.animation as animation | |
from IPython.display import HTML | |
from scipy.stats import norm | |
fig, ax = plt.subplots() | |
def update(num,x,y,scales,lines): | |
if len(lines) > 0: | |
lines.pop().remove() | |
y_ =norm.pdf(x,loc=0,scale=scales[num]) | |
line, = ax.plot(x, y_,c="m") | |
lines.append(line) | |
sig = 'σ=' | |
ax.set_title(sig + str(scales[num])[:4]) | |
ax.set_xlim(-10.5, 10.5) | |
ax.set_ylim(0, 1.1) | |
ax.set_xlabel('x') | |
ax.set_ylabel('p(x)') | |
ax.grid() | |
x = np.linspace(-10,10,100) | |
y= norm.pdf(x,loc=0,scale=1) | |
scales = np.linspace(0.05, 5.0, 100) | |
theta= np.linspace(np.pi/101, 100/101*np.pi, 100) | |
scales = 5*np.sin(theta) | |
lines = [] | |
ani = animation.FuncAnimation(fig, update, 100, fargs=(x,y,scales,lines), interval=100) | |
HTML(ani.to_html5_video()) | |
dpi=100 | |
ani.save('gauss_scale.mp4', writer="ffmpeg",dpi=dpi) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment