반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- broscoding
- KNeighborsClassifier
- web
- 자료구조
- classification
- Keras
- CES 2O21 참여
- 웹 용어
- C언어
- bccard
- mglearn
- postorder
- tensorflow
- vscode
- inorder
- 머신러닝
- web 용어
- pycharm
- html
- paragraph
- 재귀함수
- java역사
- CES 2O21 참가
- web 개발
- discrete_scatter
- 데이터전문기관
- cudnn
- web 사진
- 결합전문기관
- 대이터
Archives
- Today
- Total
bro's coding
matplotlib.animation_2 본문
반응형
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import matplotlib.animation as animation
class SubplotAnimation(animation.TimedAnimation):
def __init__(self):
fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(2, 2, 2)
ax3 = fig.add_subplot(2, 2, 4)
self.t = np.linspace(0, 80, 400)
self.x = np.cos(2 * np.pi * self.t / 10.)
self.y = np.sin(2 * np.pi * self.t / 10.)
self.z = 10 * self.t
ax1.set_xlabel('x')
ax1.set_ylabel('y')
self.line1 = Line2D([], [], color='black')
self.line1a = Line2D([], [], color='red', linewidth=2)
self.line1e = Line2D(
[], [], color='red', marker='o', markeredgecolor='r')
ax1.add_line(self.line1)
ax1.add_line(self.line1a)
ax1.add_line(self.line1e)
ax1.set_xlim(-1, 1)
ax1.set_ylim(-2, 2)
ax1.set_aspect('equal', 'datalim')
ax2.set_xlabel('y')
ax2.set_ylabel('z')
self.line2 = Line2D([], [], color='black')
self.line2a = Line2D([], [], color='red', linewidth=2)
self.line2e = Line2D(
[], [], color='red', marker='o', markeredgecolor='r')
ax2.add_line(self.line2)
ax2.add_line(self.line2a)
ax2.add_line(self.line2e)
ax2.set_xlim(-1, 1)
ax2.set_ylim(0, 800)
ax3.set_xlabel('x')
ax3.set_ylabel('z')
self.line3 = Line2D([], [], color='black')
self.line3a = Line2D([], [], color='red', linewidth=2)
self.line3e = Line2D(
[], [], color='red', marker='o', markeredgecolor='r')
ax3.add_line(self.line3)
ax3.add_line(self.line3a)
ax3.add_line(self.line3e)
ax3.set_xlim(-1, 1)
ax3.set_ylim(0, 800)
animation.TimedAnimation.__init__(self, fig, interval=50, blit=True)
def _draw_frame(self, framedata):
i = framedata
head = i - 1
head_slice = (self.t > self.t[i] - 1.0) & (self.t < self.t[i])
self.line1.set_data(self.x[:i], self.y[:i])
self.line1a.set_data(self.x[head_slice], self.y[head_slice])
self.line1e.set_data(self.x[head], self.y[head])
self.line2.set_data(self.y[:i], self.z[:i])
self.line2a.set_data(self.y[head_slice], self.z[head_slice])
self.line2e.set_data(self.y[head], self.z[head])
self.line3.set_data(self.x[:i], self.z[:i])
self.line3a.set_data(self.x[head_slice], self.z[head_slice])
self.line3e.set_data(self.x[head], self.z[head])
self._drawn_artists = [self.line1, self.line1a, self.line1e,
self.line2, self.line2a, self.line2e,
self.line3, self.line3a, self.line3e]
def new_frame_seq(self):
return iter(range(self.t.size))
def _init_draw(self):
lines = [self.line1, self.line1a, self.line1e,
self.line2, self.line2a, self.line2e,
self.line3, self.line3a, self.line3e]
for l in lines:
l.set_data([], [])
ani = SubplotAnimation()
# ani.save('test_sub.mp4')
plt.show()
반응형
'[IT] > python.matplotlib' 카테고리의 다른 글
finance (0) | 2020.06.09 |
---|---|
matplotlib.animation (0) | 2020.06.08 |
matplotlib.dist_table (0) | 2020.04.07 |
matplotlib.font_manager, rc(한글 사용하기) (0) | 2020.04.06 |
matplotlib.axis(축 다루기) (0) | 2020.04.03 |
matplotlib.savefig(그래프 저장하기) (0) | 2020.04.03 |
matplot.annotate(화살표, 그리드, 텍스트 그리기) (0) | 2020.04.03 |
matplotlib.subplot(그래프 여러개 그리기 2) (0) | 2020.04.03 |
Comments