python统计订单走势_python

#coding=utf-8

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

# ------------ 设置为系统中的中文字体------------
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei'] # linux下中文乱码处理
mpl.rcParams['font.sans-serif'] = ['Microsoft YaHei'] # windows下中文乱码处理

# plot 线形图
# bar 条形图
# scatter 点状图
# stackplot 堆叠图
CONST_FIGURE_TYPE = 'plot'

def read_csv():
    filename = "E:/work/work_git/python_personalrepo/data/order_statis_2.csv"
    # filename = 'e:\\order_statis_2.csv'
    df = pd.read_csv(filename)
    # print df.head()
    return df

# 格式化日期
def format_date(x, pos=None):
    thisindex = np.clip(int(x + 0.5), 0, len(df) - 1)
    datetime_ret = df['days'][thisindex]
    return datetime_ret

# 构建数据
def build_data_ordercount():
    x_axis_values = []
    y_axis_values = []

    # print df['days']
    for index, row in df.iterrows():
        x_axis_values.append(index)
        y_axis_values.append(row['count'])

    x_axis_values = np.arange(len(df))
    # print x_axis_values
    # print y_axis_values

    fig,ax = plt.subplots()

    ax.plot(x_axis_values, y_axis_values, 'o-',label=u'订单数量')
    # x轴标签 倾斜角度
    # plt.xticks(rotation=30)

    ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
    fig.autofmt_xdate()



    return False





# 构建数据
def build_data_ordermoney():
    x_axis_values1 = []
    y_axis_values1 = []

    for index, row in df.iterrows():
        x_axis_values1.append(index + 1)
        y_axis_values1.append(row['money']/1000.0)

    # print x_axis_values1
    # print y_axis_values1

    plt.plot(
        # X 轴
        x_axis_values1,
        # y轴
        y_axis_values1, 'ro-', label=u'订单金额')

    return False



# 绘制图形
def show_figure():
    plt.ylabel(u'订单数量')
    plt.xlabel(u'下单日期')
    plt.title(u'订单走势')
    plt.legend()

    plt.show()

    return False

if __name__ == "__main__":
    df = read_csv()
    # print df.head()
    build_data_ordercount()
    build_data_ordermoney()
    show_figure()

 

  python统计订单走势_中文乱码_02