# 作业 **Repository Path**: li-yangxi/task ## Basic Information - **Project Name**: 作业 - **Description**: 李阳希大二python课作业存放仓库 - **Primary Language**: Python - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-10-17 - **Last Updated**: 2022-06-15 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 作业 #### 介绍 李阳希大二python课 #饼图(不同地区酒店数量在全香港中的占比) plt.rcParams['font.sans-serif'] = 'SimHei' rate = df['地区'].value_counts() print(rate) labels=(['油尖旺','其他','湾仔','中西区','九龙城','东区','离岛','观塘/荃湾','葵青/南区','沙田']) label = rate.index plt.figure(figsize=(10, 6)) patches, ltext , ptext = plt.pie(rate,labels=label, autopct='%.2f%%') for x in ltext: x.set_size(4) for x in ptext: x.set_size(4) plt.title('不同地区酒店数量在全香港中的占比') plt.legend() plt.show() #多层嵌套饼图(香港酒店各个价格等级和评分等级的占比) print(df[:5]) plt.figure(figsize=(12,8)) df['价格等级']=pd.cut(df['价格'],[0,500,1000,1500,2000,2500,15000],labels=['低价酒店','较低价酒店','平价酒店','较高价酒店','高价酒店','奢华酒店']) df['评分等级']=pd.cut(df['评分'],[0.0,3.0,3.3,3.6,3.9,4.2,4.5,4.8,5.0],labels=['冷门地区','较冷门酒店','普通酒店','一般酒店','中等水平酒店','','较热门酒店','热门酒店']) print(df) x1=df['价格等级'].value_counts() x2=df['评分等级'].value_counts() print(x1) print(x2) print('*'*60) label1=x1.index label2=x2.index plt.title("香港酒店各个价格等级和评分等级的占比",y=1.08,fontsize=25,color='b') plt.pie(x1, labels=label1, autopct='%.2f%%', startangle=90, shadow=True, pctdistance=0.8, rotatelabels=True, radius=1.2, textprops={'fontsize':14,'color':'purple'}, wedgeprops={'linewidth':2,'width':0.3,'edgecolor':'k'}) plt.pie(x2, labels=label2, autopct='%.2f%%', startangle=90, shadow=True, pctdistance=0.6, rotatelabels=True, radius=0.6, textprops={'fontsize': 12, 'color': 'black'}, wedgeprops={'linewidth':2,'width':0.4,'edgecolor':'k'}) plt.legend(loc='upper left',bbox_to_anchor=(0,0),ncol=2) plt.show() #散点图(价格和评分的关系) x = df['评分'] y = df['价格'] plt.figure(figsize=(10, 8)) plt.scatter(x, y, color='b') plt.title('评分和价格') plt.xlim(2.5,5.0) plt.ylim(0,800) plt.xlabel('评分') plt.ylabel('价格') plt.show()