# 代码3-3 捞起生鱼片的季度销售情况
import pandas as pd
import numpy as np
catering_sale = 'D:/develop/Spider/data/catering_fish_congee.xls' # 餐饮数据
data = pd.read_excel(catering_sale,names=['date','sale']) # 读取数据,指定“日期”列为索引
bins = [0,500,1000,1500,2000,2500,3000,3500,4000]
labels = ['[0,500)','[500,1000)','[1000,1500)','[1500,2000)',
'[2000,2500)','[2500,3000)','[3000,3500)','[3500,4000)']
data['sale分层'] = pd.cut(data.sale, bins, labels=labels)
aggResult = data.groupby(by='sale分层').agg({'sale': np.size})
pAggResult = round(aggResult/aggResult.sum(), 2, ) * 100
import matplotlib.pyplot as plt
plt.figure(figsize=(10,6)) # 设置图框大小尺寸
pAggResult['sale'].plot(kind='bar',width=0.8,fontsize=10) # 绘制频率直方图
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.title('季度销售额频率分布直方图0437',fontsize=20)
plt.show()
import pandas as pd
import matplotlib.pyplot as plt
catering_dish_profit = 'D:/develop/Spider/data/catering_dish_profit.xls' # 餐饮数据
data = pd.read_excel(catering_dish_profit)
x = data['盈利']
labels = data['菜品名']
plt.figure(figsize = (8,6))
plt.pie(x,labels = labels)
plt.rcParams['font.sans-serif'] = 'SimHei'
plt.title('菜品销售分部(饼图)学号3037')
plt.axis('equal')
plt.show()
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_excel('D:/develop/Spider/data/dish_sale.xls')
plt.figure(figsize = (8,4))
plt.plot(data['月份'],data['A部门'],color = 'green',label = 'A部门',marker = 'o')
plt.plot(data['月份'],data['B部门'],color = 'red',label = 'B部门',marker = 's')
plt.plot(data['月份'],data['C部门'],color = 'skyblue',label = 'C部门',marker = 'x')
plt.legend()
plt.ylabel('销售额(万元)')
plt.title('学号3037')
plt.show()
data = pd.read_excel('D:/develop/Spider/data/dish_sale_b.xls')
plt.figure(figsize = (8,4))
plt.plot(data['月份'],data['2012年'],color = 'green',label = '2012年',marker = 'o')
plt.plot(data['月份'],data['2013年'],color = 'red',label = '2013年',marker = 's')
plt.plot(data['月份'],data['2014年'],color = 'skyblue',label = '2014年',marker = 'x')
plt.legend()
plt.ylabel('销售额(万元)')
plt.title('学号3037')
plt.show()
import pandas as pd
catering_sale = 'D:/develop/Spider/data/catering_sale.xls' # 餐饮数据
data = pd.read_excel(catering_sale, index_col = u'日期') # 读取数据,指定“日期”列为索引列
import matplotlib.pyplot as plt # 导入图像库
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False # 用来正常显示负号
plt.figure() # 建立图像
plt.title('学号3037',fontsize=20)
p = data.boxplot(return_type='dict') # 画箱线图,直接使用DataFrame的方法
x = p['fliers'][0].get_xdata() # 'flies'即为异常值的标签
y = p['fliers'][0].get_ydata()
y.sort() # 从小到大排序,该方法直接改变原对象
for i in range(len(x)):
if i>0:
plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i]+0.05 -0.8/(y[i]-y[i-1]),y[i]))
else:
plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i]+0.08,y[i]))
plt.show() # 展示箱线图
标签:plot,26,plt,labels,sale,label,2023.2,数据挖掘,data From: https://www.cnblogs.com/lyf238/p/17157122.html