rollingで均等線を描く

882 ワード

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt 
from mpl_finance import candlestick2_ochl


df_tmp = pd.read_csv('d:/ch5/600895.csv',encoding='gbk',index_col=0)
df = df_tmp.head(40)
print(df)

fig = plt.figure()
ax = fig.add_subplot(111)
candlestick2_ochl(ax=ax,opens=df['open'].values,closes=df['close'].values,highs=df['high'].values,lows=df['low'].values,width=0.75,colorup='red',colordown='green')

df['close'].rolling(5).mean().plot(color='red',label='5   ')
df['close'].rolling(10).mean().plot(color='blue',label='10   ')
plt.legend(loc='best')
plt.grid(True)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.xticks(range(len(df.index.values)),df.index.values,rotation=40)
plt.show()