You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.0 KiB
39 lines
1.0 KiB
import matplotlib.pyplot as plt
|
|
import pandas as pd
|
|
import pymysql
|
|
from sqlalchemy import create_engine
|
|
|
|
MYSQL_HOST = 'localhost'
|
|
MYSQL_PORT = '3306'
|
|
MYSQL_USER = 'root'
|
|
MYSQL_PASSWORD = 'root'
|
|
MYSQL_DB = 'fu_logistics'
|
|
|
|
engine = create_engine('mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8'
|
|
% (MYSQL_USER, MYSQL_PASSWORD, MYSQL_HOST, MYSQL_PORT, MYSQL_DB))
|
|
|
|
sql="""select * from orders"""
|
|
|
|
data = pd.read_sql(sql,engine)
|
|
# 将日期这一列数据提取出来
|
|
rq = data[["Odelivery_time",'Onum']]
|
|
# 将日期去重后转化为列表变成x轴数据
|
|
x_data = rq['Odelivery_time'].drop_duplicates().tolist()
|
|
|
|
# 将日期进行分组计数变为y轴数据
|
|
y_data = rq.groupby('Odelivery_time').count().reset_index()
|
|
y_data = y_data['Onum'].tolist()
|
|
# y_data.sort(reverse=True)
|
|
|
|
plt.figure()
|
|
plt.rcParams['font.sans-serif'] = ['SimHei']
|
|
|
|
plt.plot(x_data,y_data,'g^--')
|
|
plt.xlabel('日期')
|
|
plt.ylabel('新增订单')
|
|
for i in range(len(x_data)):
|
|
plt.text(x_data[i],y_data[i],y_data[i])
|
|
|
|
plt.title('新增订单走势')
|
|
|
|
plt.show() |