示例#1
0
文件: main.py 项目: ccfr32/cookbook
def save_png(df, code):
    meta = get_stock_meta(code)
    if not meta:
        print("Can't get stock(%s) meta..." % code)
        return
    industry_dir = 'png/%s' % meta['industry']
    if not os.path.exists(industry_dir):
        os.makedirs(industry_dir)
    pngpath = 'png/%s/%s.png' % (meta['industry'], code)
    if os.path.exists(pngpath):
        print("%s already exists..." % pngpath)
        return
    title = u'%s(%s)' % (meta['name'], code)
    end = datetime.datetime.now()
    start = end - datetime.timedelta(days=500)
    start_idx = int(start.strftime("%Y%m%d"))
    end_idx = int(end.strftime("%Y%m%d"))
    fig = plt.figure(facecolor='white')
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    stocklib.draw_ma(ax1, df, title=title, start=start_idx, end=end_idx)
    stocklib.draw_k(ax2, df, title=title, start=start_idx, end=end_idx)
    # plt.show()
    fig.savefig(pngpath)
    plt.close()
示例#2
0
文件: main.py 项目: ccfr32/cookbook
def show(df):
    fig = plt.figure(facecolor='white')
    ax1 = fig.add_subplot(211)
    ax2 = fig.add_subplot(212)
    stocklib.draw_ma(ax1, df, start=20150101)
    stocklib.draw_k(ax2, df, start=20150101)
    plt.show()