import json
from collections import Counter
import matplotlib.pyplot as plt
import matplotlib as mpl def extract(fpath):
# 提取数据
# 返回包含有两个元素的元组组成的列表 with open(fpath, encoding='utf-8') as f:
data = json.load(f) company_info = []
for item in data['erDataList']:
company_info.append((item['city'], item['address'])) return company_info def autolabel(rects, ax, xpos='center'):
# 给柱状图中的每一条柱添加标签 for rect in rects:
height = rect.get_height()
ax.annotate('{}'.format(height),
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3),
textcoords="offset points",
ha="center",
va="bottom") def makeChart(data):
# 制作图表 citys = [item[0] for item in data]
# addrs = [item[1] for item in data] counter = Counter(citys) # 设置画布大小,单位是 inch
fig = plt.figure(figsize=(12, 8))
ax = fig.add_subplot(1, 1, 1)
rects = ax.bar(x=list(counter.keys()),
height=list(counter.values()))
ax.set_xlabel("城市分布")
ax.set_ylabel("2004年成立企业数")
ax.set_title("广东省2004年各市新成立企业数量")
autolabel(rects, ax)
plt.show() if __name__ == '__main__': # 设置以正常显示中文字体
mpl.rcParams['font.sans-serif'] = 'SimHei'
fpath = '广西2004.json'
data = extract(fpath)
makeChart(data)

最新文章

  1. (转载)linux下各个文件夹的作用
  2. 点餐系统3个sprint的团队贡献分
  3. nginx 在windows平台上对asp.net做反向代理
  4. 以全局监听的方式处理img的error事件
  5. 使用 Redis 实现排行榜功能 (转载 https://segmentfault.com/a/1190000002694239)
  6. 关于H5中自定义属性的设置和获取
  7. RFS_关键字
  8. 死锁及oracle死锁--转载
  9. PHP empty函数判断0返回真还是假?
  10. WordPress RokIntroScroller插件‘thumb.php’多个安全漏洞
  11. android自定义倒计时控件示例
  12. Html 加载音乐代码mp3
  13. php递归函数,性能给力
  14. hdu 5445 多重背包
  15. Delphi 7中的四种消息框
  16. arcEngine开发之查看属性表
  17. GK888CN与Devexpress报表打印标签
  18. 11、Redis的持久化(RDB、AOF)
  19. Apache Rewrite(大小写)
  20. centos7 编译安装mysql

热门文章

  1. 2_Swift基本数据类型
  2. Java collection 集合类架构
  3. 源码包安装转换rpm包
  4. PHP代码篇(四)--将字符串按指定字符切割
  5. Ubantu搭建虚拟环境
  6. python获得多个输入值
  7. Linux 修改/etc/sudoers 可被任何修改,如何解决
  8. k8s中的client-go编译成功
  9. python的gRPC示例
  10. 05justify-content