本文实例讲述了Python基于matplotlib画箱体图检验异常值操作。分享给大家供大家参考,具体如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# -*- coding:utf-8 -*-
#! python3
import pandas as pd
import os
import matplotlib.pyplot as plt
data = pd.read_excel( 'catering_sale.xls' ,index_col = '日期' )
plt.rcParams[ 'font.sans-serif' ] = [ 'SimHei' ] #正常显示中文
plt.rcParams[ 'axes.unicode_minus' ] = False #正常显示负号
plt.figure(figsize = ( 8 , 8 ))
p = data.boxplot(return_type = 'dict' )
x = p[ 'fliers' ][ 0 ].get_xdata()
y = p[ 'fliers' ][ 0 ].get_ydata()
y.sort()
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.8 ,y[i]))
plt.show()
|
运行结果:
附:catering_sale.xls点击此处本站下载。
希望本文所述对大家Python程序设计有所帮助。
原文链接:https://blog.csdn.net/qq_26948675/article/details/79298052