p = data.boxplot() #画箱线图,直接使用DataFrame的方法 过程中出现错误
2018-03-18 17:26
357 查看
运行下面代码的时候出现错误:
#-*- coding: utf-8 -*-
import pandas as pd
catering_sale = '/Users/gongyanpeng/Downloads/图书资料/Python数据分析与挖掘实战/图书配套数据、代码/chapter3/demo/data/catering_sale.xls'
data = pd.read_excel(catering_sale, index_col = u'日期') #读取数据,指定“日期”列为索引列
import matplotlib.pyplot as plt #导入图像库
plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
plt.figure() #建立图像
p = data.boxplot() #画箱线图,直接使用DataFrame的方法
x = p['fliers'][0].get_xdata() # 'flies'即为异常值的标签
y = p['fliers'][0].get_ydata()
y.sort() #从小到大排序,该方法直接改变原对象
#用annotate添加注释
#其中有些相近的点,注解会出现重叠,难以看清,需要一些技巧来控制。
#以下参数都是经过调试的,需要具体问题具体调试。
for i in range(len(x)):
if i>0:
plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i]+0.05 -0.8/(y[i]-y[i-1]),y[i]))
else:
plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i]+0.08,y[i]))
plt.show() #展示箱线图
报错为:TypeError: 'AxesSubplot' object is not subscriptable
#-*- coding: utf-8 -*-
import pandas as pd
catering_sale = '/Users/gongyanpeng/Downloads/图书资料/Python数据分析与挖掘实战/图书配套数据、代码/chapter3/demo/data/catering_sale.xls'
data = pd.read_excel(catering_sale, index_col = u'日期') #读取数据,指定“日期”列为索引列
import matplotlib.pyplot as plt #导入图像库
plt.rcParams['font.sans-serif'] = ['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False #用来正常显示负号
plt.figure() #建立图像
p = data.boxplot() #画箱线图,直接使用DataFrame的方法
x = p['fliers'][0].get_xdata() # 'flies'即为异常值的标签
y = p['fliers'][0].get_ydata()
y.sort() #从小到大排序,该方法直接改变原对象
#用annotate添加注释
#其中有些相近的点,注解会出现重叠,难以看清,需要一些技巧来控制。
#以下参数都是经过调试的,需要具体问题具体调试。
for i in range(len(x)):
if i>0:
plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i]+0.05 -0.8/(y[i]-y[i-1]),y[i]))
else:
plt.annotate(y[i], xy = (x[i],y[i]), xytext=(x[i]+0.08,y[i]))
plt.show() #展示箱线图
报错为:TypeError: 'AxesSubplot' object is not subscriptable
此时,只需要把p = data.boxplot() 改为:
p = data.boxplot(return_type='dict') #画箱线图,直接使用DataFrame的方法这样报错就不会出现。
相关文章推荐
- Android刷机(卡刷)详细过程,出现刷机失败错误的解决方法,以及乐蛙OS的使用感受(小评测)
- 使用win7过程中出现错误1079代码故障的解决方法
- win7使用过程中出现错误1079故障的原因及解决方法
- CocoaPods 的详细安装步骤,使用方法以及安装过程中出现的各种错误总结
- 如何解决FormView中实现DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 使用OleDbCommandBuilder时出现“Insert into 语句的语法错误”的解决方法
- 使用ajax过程中出现未知错误
- 使用ExternalInterface.call方法,出现js错误(解决方法)
- 使用OleDbCommandBuilder时出现“Insert into 语句的语法错误”的解决方法
- (System)使用windows更新出现0x8DDD0018编号错误的解决方法
- Delphi使用BDE连接远程MS SQL SERVER 2000数据库时出现“Db-library network communciations layer not loaded.”错误的解决方法
- 使用OleDbCommandBuilder时出现“Insert into 语句的语法错误”的解决方法
- .net 中使用Excel library 11.0 COM Workbooks.Open 出现错误:System.MissingMethodException: 找不到方法
- 引用天下会"使用OleDbCommandBuilder时出现“Insert into 语句的语法错误”的解决方法"
- 使用OleDbCommandBuilder时出现“Insert into 语句的语法错误”的解决方法
- 使用AjaxPro出现错误(没有找到适合的方法来重写)
- DropDownList连动选择时出现 "Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用" 的错误
- 关于使用ASP.NE 1.1发送电子邮件时出现的 未能访问“CDO.Message”对象 的错误的解决方法
- 系统在启动过程中出现的错误提示及处理方法
- 安装DriverStudio3.2 过程中出现DSDDKEnv8.dll failed to register错误的解决方法