import pandas as pd import matplotlib.pyplot as plt #导入绘图包 plt.rcParams['font.sans-serif'] = ['SimHei'] #解决中文显示问题 plt.rcParams['axes.unicode_minus'] = False # 解决中文显示问题 url = r"D:\大三\数据分析\实训1\catering_dish_profit.xls" data = pd.read_excel(url) #饼图 plt.figure(figsize=(6,6))#将画布设定为正方形,则绘制的饼图是正圆 plt.pie(data['盈利'], labels=data['菜品名']) plt.title('菜品销售量分布饼图\n学号:3033') #加标题 plt.show() #条形图 plt.figure(figsize=(8,4)) plt.bar(data['菜品名'],data['盈利']) plt.xlabel('菜品') plt.ylabel('销量') plt.title('菜品销售量条形图\n学号:3033') #加标题 plt.show()
# -*- coding: utf-8 -*- """ Created on Mon Feb 27 10:52:51 2023 @author: 10320 """ import numpy as np import matplotlib.pyplot as plt #导入绘图包 import math plt.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Π)的函数图象\n学号3033') #加标题 plt.xlabel('X') plt.ylabel('Y') plt.legend() #显示图例 plt.show()
# -*- coding: utf-8 -*- """ Created on Mon Feb 27 10:54:25 2023 @author: 10320 """ import pandas as pd import matplotlib.pyplot as plt #导入绘图包 plt.rcParams['font.sans-serif'] = ['SimHei'] #解决中文显示问题 plt.rcParams['axes.unicode_minus'] = False # 解决中文显示问题 url = r"D:\大三\数据分析\实训1\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('菜品销售量折线对比图\n学号:3033') #加标题 plt.legend() #显示图例 plt.show()
# -*- coding: utf-8 -*- """ Created on Mon Feb 27 10:54:26 2023 @author: 10320 """ import pandas as pd import matplotlib.pyplot as plt import numpy as np ##读取数据 url = r"D:\大三\数据分析\实训1\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('季度销售额箱型图\n学号:3033') #加标题 # 直方图 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('季度销售额频率分布直方图\n学号:3033',fontsize=20) plt.show()
标签:绘图,plt,Python,sale,用于,pd,rcParams,import,data From: https://www.cnblogs.com/LianGiQ/p/17158925.html