728x90
반응형
'''###########################
plot animation
###########################'''
import pandas_datareader as pdr
from pandas import to_numeric
import datetime
from datetime import timedelta
import numpy as np
import pandas as pd
import warnings
from scipy.ndimage import gaussian_filter1d
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
code = '069500'
name = 'KODEX200'
# code = '006260'
# name = 'LS'
test_start = '2020-01-01'
test_end = '2023-12-31'
GAMMA = 4
# 데이터 생성
last_day = 352
df = pdr.DataReader(code, "naver", test_start, test_end)
df = df.apply(to_numeric)
df.columns = ['Open', 'High', 'Low', 'Close', 'Volume']
fig, ax = plt.subplots(figsize=(12,6))
ax.set_xlim(0, len(df))
ax.set_ylim(min(df['Close']), max(df['Close']))
ax.grid()
x, y = [], []
pt_close, = plt.plot([], label='Close')
pt_ga, = plt.plot([], label='Gaussian')
def update(frame):
x.append(len(x))
y.append(frame)
pt_close.set_data(x, y)
g = gaussian_filter1d(y, sigma=4)
pt_ga.set_data(x, g)
return frame,
%matplotlib qt5
# %matplotlib inline
ani = FuncAnimation(fig, update, frames=df['Close'].tolist())
# plt.show()
ani.save('stock_gaussian.gif', writer='imagemagick')
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] Flask를 사용해 웹서버 만들기 (외부에서 접속하기) (0) | 2023.07.19 |
---|---|
[파이썬] 주식 차분 Plot (0) | 2023.07.18 |
[파이썬] Plot 애니메이션 (matplotlib.animation) (0) | 2023.07.18 |
[파이썬] Gaussian Filter기반의 Time-series Denoising(노이즈 제거) (0) | 2023.07.18 |
[파이썬] Bilateral Filter기반의 Time-series Denoising(노이즈 제거) (0) | 2023.07.18 |
댓글