Skip to content

Instantly share code, notes, and snippets.

Created December 24, 2019 12:40
What would you like to do?
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.animation as animation
def make_sin(x, amp, T=100):
noise = amp * np.random.randint(-10, 10, len(x))
return np.sin(2*np.pi*x/T) + noise
x = np.arange(200)
y = make_sin(x, 0.01)
l = 25
def make_dataset(y, l):
data = []
target = []
for i in range(len(y)-l):
target.append(y[i + l])
return(data, target)
(data, target) = make_dataset(y, l)
data = np.array(data).reshape(175, 25, 1)
fig = plt.figure()
plt.xlim(-10, 210)
plt.ylim(-1.5, 1.5)
plt.plot(x, y, color='lightgray')
ims = []
for i in range(175):
im1 = plt.plot(x[i: i+25], y[i: i+25], color='blue')
im2 = plt.plot(x[i+25], y[i+25], color='red', marker = 'o', markersize = 10)
ani = animation.ArtistAnimation(fig, ims,interval=200)
#GIFファイルとして保存'output.gif', writer='imagemagick')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment