Last active
March 22, 2017 08:10
-
-
Save ronekko/cbf017d39244068bb852d8d69a3712e7 to your computer and use it in GitHub Desktop.
matplotlibで一つのfigureウィンドウの内容を逐次的に更新してアニメーションする
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 -*- | |
""" | |
Created on Wed Mar 22 16:44:14 2017 | |
@author: sakurai | |
""" | |
import numpy as np | |
import matplotlib.pyplot as plt | |
plt.ion() | |
t_begin = 0 | |
t_end = 10 * np.pi | |
t_num = 200 | |
x = [] | |
y = [] | |
(line,) = plt.plot(x, y) | |
for t in np.linspace(t_begin, t_end, t_num): | |
x_t = t * np.cos(t) | |
y_t = t * np.sin(t) | |
x.append(x_t) | |
y.append(y_t) | |
line.set_xdata(x) | |
line.set_ydata(y) | |
max_abs = np.absolute(np.concatenate((x, y))).max() | |
plt.xlim([-max_abs, max_abs]) | |
plt.ylim([-max_abs, max_abs]) | |
plt.draw() | |
plt.pause(0.01) | |
plt.ioff() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment