# -*- coding: utf-8 -*-
"""
Spyder Editor
This is a temporary script file.
"""
import pandas as pd
from matplotlib import pyplot as plt
##读取数据
url = r"F:\data\catering_fish_congee.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('箱型图:3043') #加标题
# 直方图
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('条形图:3043',fontsize=20)
plt.show()
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 26 19:05:06 2023
@author: LIUYUEXIANG
"""
import pandas as pd
import matplotlib.pyplot as plt #导入绘图包
plt.rcParams['font.sans-serif'] = ['SimHei'] #解决中文显示问题
plt.rcParams['axes.unicode_minus'] = False # 解决中文显示问题
url = r"F:\data\catering_dish_profit.xls"
data = pd.read_excel(url)
#饼图
plt.figure(figsize=(6,6))#将画布设定为正方形,则绘制的饼图是正圆
plt.pie(data['盈利'], labels=data['菜品名'])
plt.title('饼图:3043') #加标题
plt.show()
#条形图
plt.figure(figsize=(8,4))
plt.bar(data['菜品名'],data['盈利'])
plt.xlabel('菜品')
plt.ylabel('销量')
plt.title('条形图:3043') #加标题
plt.show()
#散点图
years = data['菜品名']
turnovers = data['盈利']
plt.figure()
plt.scatter(years, turnovers, c='red', s=100, label='销量')
plt.xlabel("菜品", fontdict={'size': 16})
plt.ylabel("销量", fontdict={'size': 16})
plt.title("散点图:3043", fontdict={'size': 20})
plt.legend(loc='best')
plt.show()
标签:数据分析,plt,figure,title,python,sale,3043,data From: https://www.cnblogs.com/jiujiuwawa/p/17157468.html