python : pandas , matplotlib 批量绘图

python 2.7

pip install pandas-0.19.2-cp27-cp27m-win32.whl

for_roll_mean.py

# -*- coding: utf-8 -*-
import glob
import pandas as pd

import matplotlib.pyplot as plt
# 加这个两句 可以显示中文
plt.rcParams['font.sans-serif'] = [u'SimHei']
plt.rcParams['axes.unicode_minus'] = False

for f1 in glob.glob("*.csv"):
    df = pd.read_csv(f1, parse_dates=True, index_col=0 )
    fcode = f1.split('.')[0]
    fname =u'基金净值图'
    
    df['jz'].plot(figsize=(10,5),grid=True,legend='jz',label=fcode,title=fname)
    # 画60日移动平均线  
    pd.rolling_mean(df['jz'], 60).plot(grid=True)
    f2 = fcode +'.png'
    print f2
    plt.savefig(f2)
    plt.close()    # 这句很必要
#

 

你可能感兴趣的:(python)