#coding=utf-8
importnumpy as npimportpandas as pdimportmatplotlib.pyplot as pltimportmatplotlib.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'
defread_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()
returndf#格式化日期
def format_date(x, pos=None):
thisindex= np.clip(int(x + 0.5), 0, len(df) - 1)
datetime_ret= df['days'][thisindex]returndatetime_ret#构建数据
defbuild_data_ordercount():
x_axis_values=[]
y_axis_values=[]#print df['days']
for index, row indf.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()returnFalse#构建数据
defbuild_data_ordermoney():
x_axis_values1=[]
y_axis_values1=[]for index, row indf.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'订单金额')returnFalse#绘制图形
defshow_figure():
plt.ylabel(u'订单数量')
plt.xlabel(u'下单日期')
plt.title(u'订单走势')
plt.legend()
plt.show()returnFalseif __name__ == "__main__":
df=read_csv()#print df.head()
build_data_ordercount()
build_data_ordermoney()
show_figure()