import pandas as pd
catering_sale=(r'D:\数据挖掘\catering_sale.xls')
data=pd.read_excel(catering_sale,index_col='日期')
print(data.describe())
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
plt.figure()
p=data.boxplot(return_type='dict')
x=p['fliers'][0].get_xdata()
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.title("箱型图3116")
plt.show()
# 代码3-3 捞起生鱼片的季度销售情况
import pandas as pd
import numpy as np
catering_sale = (r'D:\数据挖掘\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('sale分层').agg({'sale':'count'})
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('季度销售额频率分布直方图3116',fontsize=20)
catering_dish_profit= (r'D:\数据挖掘\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.axis('equal')
plt.title('菜品销售量饼图3116',fontsize=20)
plt.show()
x=data['菜品名']
y=data['盈利']
plt.figure(figsize=(8,4))
plt.bar(x,y)
plt.rcParams['font.sans-serif']='SimHei'
plt.xlabel('菜品')
plt.ylabel('销量')
plt.title('菜品销售量分布(条形图)3116')
plt.show()
dish_sale= (r'D:\数据挖掘\data\dish_sale.xls')
data=pd.read_excel(dish_sale)
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('部门销售额比较3116',fontsize=20)
plt.show()
dish_sale_b= (r'D:\数据挖掘\data\dish_sale_b.xls')
data=pd.read_excel(dish_sale_b)
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('各年份销售额比较3116',fontsize=20)
plt.show()
import numpy as np
x=np.linspace(0,2*np.pi,25,endpoint=True)
s=np.sin(x)
plt.figure()
plt.plot(x,s,'b-*')
plt.xlabel("x")
plt.ylabel("y")
plt.title("y=sin(x)3116")
plt.legend("sin(x)")
plt.show()
import matplotlib.pyplot as plt
years = [2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
turnovers = [0.5, 9.36, 52, 191, 350, 571, 912, 1027, 1682, 2135, 2684]
plt.figure()
plt.scatter(years, turnovers, c='orange', s=50, label='legend')
plt.xticks(range(2008, 2020, 3))
plt.yticks(range(0, 3200, 800))
plt.xlabel("Year", fontdict={'size': 16})
plt.ylabel("number", fontdict={'size': 16})
plt.title("Title3116", fontdict={'size': 20})
plt.legend(loc='best')
plt.show()
import numpy as np
example_list=[]
n=10000
for i in range(n):
tmp=[np.random.normal()]
example_list.extend(tmp)
width=100
n, bins, patches = plt.hist(example_list,bins = width,color='blue',alpha=0.5)
X = bins[0:width]+(bins[1]-bins[0])/2.0
Y = n
maxn=max(n)
maxn1=int(maxn%8+maxn+8*2)
ydata=list(range(0,maxn1+1,maxn1//8))
yfreq=[str(i/sum(n)) for i in ydata]
plt.plot(X,Y,color='green') #利用返回值来绘制区间中点连线
p1 = np.polyfit(X, Y, 7) #利用7次多项式拟合,返回拟多项式系数,按照阶数从高到低排列
Y1 = np.polyval(p1,X)
plt.plot(X,Y1,color='red')
plt.xlim(-2.5,2.5)
plt.ylim(0)
plt.yticks(ydata,yfreq) #这条语句控制纵坐标是频数或频率,打开是频率,否则是频数
plt.legend(['midpoint','fitting'],ncol=1,frameon=False)
plt.title("title3116", fontdict={'size': 20})
plt.show()
df_normal=pd.read_csv(r'D:\数据挖掘\data\user.csv')
plt.figure(figsize=(8,4))
plt.plot(df_normal["Date"],df_normal["Eletricity"])
plt.xlabel("日期")
x_major_locator=plt.MultipleLocator(7)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
plt.ylabel("每日电量")
plt.title("正常用户用电趋势3116")
plt.rcParams['font.sans-serif']=['SimHei']
plt.show()
df_steal=pd.read_csv(r'D:\数据挖掘\data\Steal user.csv')
plt.figure(figsize=(10,9))
plt.plot(df_normal["Date"],df_steal["Eletricity"])
plt.xlabel("日期")
plt.ylabel("日期")
x_major_locator=plt.MultipleLocator(7)
ax=plt.gca()
ax.xaxis.set_major_locator(x_major_locator)
plt.title("窃电用户电量趋势3116")
plt.rcParams['font.sans-serif']=['SimHei']
plt.show()
标签:plot,plt,title,python,show,sale,绘图,数据挖掘,data From: https://www.cnblogs.com/Nothingtolose/p/17155639.html