栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

绘制饼图和熊猫数据框表

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

绘制饼图和熊猫数据框表

看一下代码:

import pandas as pdimport matplotlib.pyplot as pltfrom pandas.tools.plotting import table# sample dataraw_data = {'officer_name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],        'jan_arrests': [4, 24, 31, 2, 3],        'feb_arrests': [25, 94, 57, 62, 70],        'march_arrests': [5, 43, 23, 23, 51]}df = pd.Dataframe(raw_data, columns = ['officer_name', 'jan_arrests', 'feb_arrests', 'march_arrests'])df['total_arrests'] = df['jan_arrests'] + df['feb_arrests'] + df['march_arrests']plt.figure(figsize=(16,8))# plot chartax1 = plt.subplot(121, aspect='equal')df.plot(kind='pie', y = 'total_arrests', ax=ax1, autopct='%1.1f%%',  startangle=90, shadow=False, labels=df['officer_name'], legend = False, fontsize=14)# plot tableax2 = plt.subplot(122)plt.axis('off')tbl = table(ax2, df, loc='center')tbl.auto_set_font_size(False)tbl.set_fontsize(14)plt.show()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/611863.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号