반응형
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
- discrete_scatter
- KNeighborsClassifier
- 데이터전문기관
- pycharm
- java역사
- vscode
- C언어
- paragraph
- broscoding
- CES 2O21 참가
- 대이터
- Keras
- 자료구조
- web 개발
- 머신러닝
- inorder
- classification
- web
- web 용어
- CES 2O21 참여
- 결합전문기관
- cudnn
- mglearn
- bccard
- tensorflow
- 웹 용어
- web 사진
- html
- postorder
- 재귀함수
Archives
- Today
- Total
bro's coding
finance 본문
반응형
import FinanceDataReader as fdr
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
from matplotlib import style
from matplotlib import font_manager, rc
from matplotlib import gridspec
import csv
from mpl_finance import candlestick_ohlc
from datetime import date
font_name=font_manager.FontProperties(fname="C:/Windows/Fonts/HMFMPYUN.TTF").get_name()
rc('font',family=font_name)
fig=plt.figure()
ax1=plt.subplot2grid((2,2),(0,0))
ax2=plt.subplot2grid((2,2),(0,1))
ax3=plt.subplot2grid((2,2),(1,0),colspan=2)
def drawBirths():
global ax3
years=range(1880,2012)
pieces=[]
# data 경로 설정
datafile='data/births.txt'
with open(datafile,'rt') as f:
data=csv.reader(f,delimiter=',')
for d in data:
pieces.append(d)
x=[int(year) for year,female,male in pieces]
y1=[int(female) for year,female,male in pieces]
y2=[int(male) for year,female,male in pieces]
ax3.plot(x,y1,'-',color='r',label='여아')
ax3.plot(x,y2,'-',color='b',label='남아')
ax3.grid(True)
ax3.legend(loc=4)
def viewStockTrend_1():
global ax1
df = fdr.DataReader("005930", '2019')
ref_price =43000
date=df.index
opn=np.array(df['Open'].astype(int))
high=np.array(df['High'].astype(int))
low=np.array(df['Low'].astype(int))
closep=np.array(df['Close'].astype(int))
volume=np.array(df['Volume'].astype(int))
change=np.array(df['Change'].astype(int))
ax1.plot([],[],linewidth=5,label='이익',color='r',alpha=0.5)
ax1.plot([],[],linewidth=5,label='손해',color='b',alpha=0.5)
ax1.fill_between(date, closep, ref_price, where=(closep > ref_price),
facecolor='r', alpha=0.5)
ax1.fill_between(date, closep, ref_price, where=(closep < ref_price),
facecolor='b', alpha=0.5)
ax1.spines['left'].set_color('c')
ax1.spines['left'].set_linewidth(5)
ax1.spines['right'].set_visible(False)
ax1.spines['top'].set_visible(False)
ax1.plot_date(date, closep, '-', color='b')
for label in ax1.xaxis.get_ticklabels():
label.set_rotation(45)
ax1.tick_params(axis='x', colors='r')
ax1.tick_params(axis='y', colors='#225588')
ax1.grid(True)
def drawStockTrend2():
global ax2
ref_price = 43000
df = fdr.DataReader("005930", '2015')
arrayData = np.array(df)
#date = df.index.
dates = pd.to_datetime(df.index, format="%Y-%m-%d")
# print(type(date[0]))
closeps = np.array(df['Close']).astype(int)
highs = np.array(df['High']).astype(int)
lows = np.array(df['Low']).astype(int)
openps = np.array(df['Open']).astype(int)
volumes = np.array(df['Volume']).astype(int)
# ax3에 주가 캔들을 그립니다.
ohlc = []
for i in range(len(dates)):
d = mdates.date2num(dates[i])
stock_data = d, openps[i], highs[i], lows[i], closeps[i], volumes[i]
ohlc.append(stock_data)
candlestick_ohlc(ax2, ohlc, width=0.5, colorup='r', colordown='b')
# candlestick_ohlc(ax2, zip(mdates.date2num(dates), df['Open'], df['High'], df['Low'], df['Close']),
# width=0.5, colorup="r", colordown="b")
ax2.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
ax2.xaxis.set_major_locator(mticker.MaxNLocator(10))
for label in ax2.xaxis.get_ticklabels():
label.set_rotation(45)
ax2.grid(True)
drawBirths()
viewStockTrend_1()
drawStockTrend2()
plt.show()
반응형
'[IT] > python.matplotlib' 카테고리의 다른 글
matplotlib.animation_2 (0) | 2020.06.08 |
---|---|
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