原文链接:http://www.juzicode.com/archives/3273

错误提示:

利用pandas绘制多个子图时报错:AttributeError: ‘list’ object has no attribute ‘get_figure’

#juzicode.com #vx:桔子code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rc('font',family='Youyuan',size='11')
plt.rc('axes',unicode_minus='False')t = np.arange(0, 10, 0.1)  #100行,用作index
s = np.random.randn(100,5) #100行5列的随机数据
df = pd.DataFrame(s, index=t,columns=['A1','B2','C3','D4','E4'])
df = df.cumsum() #累加fig,axes=plt.subplots(3,3,figsize=(10,10))
group = [axes[0][0], axes[0][2], axes[1][1], axes[2][0], axes[2][2]]
df.plot(title='随机曲线 by桔子code',  ax=group)
plt.show()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-29-5b24a5692d3e> in <module>13 fig,axes=plt.subplots(3,3,figsize=(10,10))14 group = [axes[0][0], axes[0][2], axes[1][1], axes[2][0], axes[2][2]]
---> 15 df.plot(title='随机曲线 by桔子code',  ax=group)16 plt.show()d:\python\python38\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)947                     data.columns = label_name948
--> 949         return plot_backend.plot(data, kind=kind, **kwargs)950 951     __call__.__doc__ = __doc__d:\python\python38\lib\site-packages\pandas\plotting\_matplotlib\__init__.py in plot(data, kind, **kwargs)59             kwargs["ax"] = getattr(ax, "left_ax", ax)60     plot_obj = PLOT_CLASSES[kind](data, **kwargs)
---> 61     plot_obj.generate()62     plot_obj.draw()63     return plot_obj.resultd:\python\python38\lib\site-packages\pandas\plotting\_matplotlib\core.py in generate(self)268         self._args_adjust()269         self._compute_plot_data()
--> 270         self._setup_subplots()271         self._make_plot()272         self._add_table()d:\python\python38\lib\site-packages\pandas\plotting\_matplotlib\core.py in _setup_subplots(self)329                 axes = fig.add_subplot(111)330             else:
--> 331                 fig = self.ax.get_figure()332                 if self.figsize is not None:333                     fig.set_size_inches(self.figsize)AttributeError: 'list' object has no attribute 'get_figure'

错误原因:

1、pandas DataFrame实例的plot()方法绘制多个子图时,没有传入subplots入参。

解决方法:

1、在plot()方法中传入subplots=True:df.plot(title=’随机曲线 by桔子code’, subplots=True, ax=group) 。

#juzicode.com #vx:桔子code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.rc('font',family='Youyuan',size='11')
plt.rc('axes',unicode_minus='False')t = np.arange(0, 10, 0.1)  #100行,用作index
s = np.random.randn(100,5) #100行5列的随机数据
df = pd.DataFrame(s, index=t,columns=['A1','B2','C3','D4','E4'])
df = df.cumsum() #累加fig,axes=plt.subplots(3,3,figsize=(10,10))
group = [axes[0][0], axes[0][2], axes[1][1], axes[2][0], axes[2][2]]
df.plot(title='随机曲线 by桔子code', subplots=True, ax=group)
plt.show()

相关阅读:

  • 数据可视化~pandas绘图
  • 数据可视化~matplotlib显示多个子图

Python错误集锦:pandas绘制多个子图时报错:AttributeError: ‘list’ object has no attribute ‘get_figure’相关推荐

  1. python使用Axes3D画三维图加入legend图例时报错AttributeError: ‘Poly3DCollection‘ object has no attribute ‘_edgecolo

    Q:python使用Axes3D画三维图加入legend图例时报错AttributeError: 'Poly3DCollection' object has no attribute '_edgeco ...

  2. 关于在《python编程从入门到实践》书中练习“外星人大战”报错“AttributeError: ‘AlienInvasion‘ object has no attribute ‘blit‘”

    关于在<python编程从入门到实践>书中练习"外星人大战"报错"AttributeError: 'AlienInvasion' object has no ...

  3. python爬虫数据寻找过程(解决爬虫异步导致AttributeError: 'NoneType' object has no attribute 'find_all'错误)

    前边写了url的分析 我们爬取想要的数据,一般是打开网站链接,用浏览器的elements功能对网页标签进行数据分析,确定想要的数据的位置,再在代码中通过requests库的get和post方式发起请求 ...

  4. python 执行报错AttributeError: 'list' object has no attribute 'g'

    ^ SyntaxError: invalid syntax E:\数学-机器学习-西瓜书-周志华\UDACITY购课\project1 矩阵操作>python test.py Traceback ...

  5. python中使用ZADD方法报错AttributeError: 'int' object has no attribute 'items'

    redis的版本关系 正确的完整实例如下: import pymongo import redis# 代码作用是mongodb的数据传送到redis中去 handler = pymongo.Mongo ...

  6. Python之报错AttributeError:'CocaCola' object has no attribute 'local_logo'

    试运行class类的代码如下,然而有报错信息:AttributeError:'CocaCola' object has no attribute 'local_logo' class CocaCola ...

  7. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    解决方法:xx.py文件名时,xx不要是python保留字 原理:因为使用了Python系统库的名字,所以在编译的时候才会产生.pyc文件. 正常的Python文件在编译运行的时候是不会产生.pyc文 ...

  8. python的mysql数据查询及报错AttributeError: 'Connection' object has no attribute 'curson'

    import pymysql #创建连接 con = pymysql.connect(host='localhost',user='root',password='123456',port=3306, ...

  9. Python脚本报错AttributeError: ‘module’ object has no attribute’get’解决方法

    发现代码都没有错.后来是改成这样: def pprint():name=var.get()print(name) var=StringVar() Label(root,text='姓名:',font= ...

最新文章

  1. 线性表元素的区间删除
  2. linux centos7 root密码重置方法
  3. dockerfile 中的 multi-stage 多阶段构建
  4. 这就是爱?英特尔处理器将整合AMD HBM2 GPU
  5. 小姐姐亲身体验:在阿里数据库科研团队实习是种怎样的体验?
  6. [solr] - solr5.2.1环境搭建 - 使用solr自带的jetty服务器
  7. 选择适合你的开源 OLAP 引擎
  8. 利用React/anu编写一个弹出层
  9. UnityShader - 模拟动态光照特效
  10. Swing 设置无边框Frame
  11. 网抑云音乐.ncm加密格式转换mp3
  12. 【基本算法】概率算法
  13. 5G虚拟专网七大典型行业案例!(附下载)
  14. 云服务器安装Linux桌面,centos 云服务器有桌面吗 如何进行安装
  15. VTCP QIO技术解析
  16. 人工智能带来的岗位减少更多是重复性、机械性、门槛低的岗位
  17. 基于jsp+mysql+Spring+SpringMVC+mybatis的ssm汽车配件管理系统
  18. Java微服务框架一览
  19. python_pandas操作-数值上下滑动一个格
  20. 传圆通老板娘2.3亿元购香港豪宅 税金达5400万

热门文章

  1. rating vs nominal 额定和标称区别
  2. 题目二:课程设计报告
  3. Android深度开发第8章随笔感悟
  4. 简述对css盒子模型的理解_css 盒子模型理解
  5. Flutter实战项目-第八篇 监听键盘弹起
  6. 苹果选了天猫 天猫成了618
  7. php 简繁体转换类库,OpenCC for PHP 优雅的简繁体转换
  8. windows如何删除默认打开方式
  9. 急!求各位学长大佬拯救!!
  10. Java URL下载图片无法打开问题