import pandas as pd
import matplotlib.pyplot as plt
import numpy as np##读取数据
url = r'C:/Users/asus/Desktop/catering_fish_congee(1).xls'
data = pd.read_excel(url,names=['date','sale'])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()
plt.title('季度销售额箱型图--number:3036') #加标题
# 直方图
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分层'])['sale'].agg([("sale","count")])pAggResult = round(aggResult/aggResult.sum(), 2, ) * 100
plt.figure(figsize=(10,6)) # 设置图框大小尺寸
pAggResult['sale'].plot(kind='bar',width=0.8,fontsize=10) # 绘制频率直方图
plt.title('季度销售额频率分布直方图--number:3036',fontsize=20)
plt.show()
import pandas as pd
import matplotlib.pyplot as plt #导入绘图包plt.rcParams['font.sans-serif'] = ['SimHei'] #解决中文显示问题
plt.rcParams['axes.unicode_minus'] = False # 解决中文显示问题url = r"C:\Users\asus\Desktop\data\catering_dish_profit.xls"
data = pd.read_excel(url)#饼图
plt.figure(figsize=(6,6))#将画布设定为正方形,则绘制的饼图是正圆
plt.pie(data['盈利'], labels=data['菜品名'])
plt.title('菜品销售量分布饼图--number:3036') #加标题
plt.show()
#条形图
plt.figure(figsize=(8,4))
plt.bar(data['菜品名'],data['盈利'])
plt.xlabel('菜品')
plt.ylabel('销量')
plt.title('菜品销售量条形图--number:3036') #加标题
plt.show()
import pandas as pd
import matplotlib.pyplot as plt #导入绘图包plt.rcParams['font.sans-serif'] = ['SimHei'] #解决中文显示问题
plt.rcParams['axes.unicode_minus'] = False # 解决中文显示问题url = r"C:\Users\asus\Desktop\data\dish_sale.xls"
data = pd.read_excel(url) #画折线图对比数据
plt.figure(figsize=(12,8))
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.xlabel('月份')
plt.ylabel('销售额(万元)')
plt.title('菜品销售量折线对比图--number:3036') #加标题
plt.legend() #显示图例
plt.show()
import numpy as np
import matplotlib.pyplot as plt #导入绘图包
import mathplt.rcParams['font.sans-serif'] = ['SimHei'] #解决中文显示问题
plt.rcParams['axes.unicode_minus'] = False # 解决中文显示问题x=np.arange(0,2*math.pi,0.1)#以0.1为单位,生成0到6的数据
y=np.sin(x)plt.figure(figsize=(12,8))
plt.plot(x,y,color='skyblue',label='f(x)=sin x',marker='o')
plt.title('f(x)=sin x在(0,2Π)的函数图象--number:3036') #加标题
plt.xlabel('X')
plt.ylabel('Y')
plt.legend() #显示图例
plt.show()