国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > Python > 正文

Python箱型圖繪制與特征值獲取過程解析

2024-09-09 19:02:23
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了Python箱型圖繪制與特征值獲取過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

它主要用于反映原始數據分布的特征,還可以進行多組數據分布特征的比較

如何利用Python繪制箱型圖

需要的import的包

 import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties import numpy as np import pandas as pd

該函數是繪制多箱型圖,且數據長度不一致的情況,input_dict = {filename1:[a1,a2,...,an],filename2:[b1,b2,...,bn]...} Y_label = 'Img_name'

def DrawMultBoxPic(input_dict,Y_label):  dict_list_length = []  for item in input_dict:    temp_length = len(input_dict[item])    dict_list_length.append(temp_length)  # 獲取最長列表長度  max_length = max(dict_list_length)  # 每個列表在后面追加None  for item in input_dict:    diff_length = max_length - len(input_dict[item])    if diff_length > 0:      for i in range(diff_length):        input_dict[item].append(None)    # else:      # print('{}文件列表長度最長'.format(item))  # 繪制箱型圖  zhfont = FontProperties(fname='C:/Windows/Fonts/simsun.ttc', size=16)  data = pd.DataFrame.from_dict(input_dict)  data.boxplot(widths=0.3,figsize=(30,15),fontsize=16)  plt.xlabel(u'煤質文件名稱', fontproperties=zhfont)  plt.ylabel(Y_label, fontproperties=zhfont)  plt.title(Y_label, fontproperties=zhfont)  # plt.axis([0, 6, 0, 90])  plt.grid(axis='y', ls='--', lw=2, color='gray', alpha=0.4)  plt.grid(axis='x', ls='--', lw=2, color='gray', alpha=0.4)  imgname = 'E://' + Y_label + '.png'  plt.savefig(imgname, bbox_inches = 'tight')  # plt.show()

結果顯示

如何獲取箱型圖特征

"""【函數說明】獲取箱體圖特征【輸入】 input_list 輸入數據列表【輸出】 out_list:列表的特征[下限,Q1,Q2,Q3,上限] 和 Error_Point_num:異常值數量【版本】 V1.0.0【日期】 2019 10 16"""def BoxFeature(input_list):  # 獲取箱體圖特征  percentile = np.percentile(input_list, (25, 50, 75), interpolation='linear')  #以下為箱線圖的五個特征值  Q1 = percentile[0]#上四分位數  Q2 = percentile[1]  Q3 = percentile[2]#下四分位數  IQR = Q3 - Q1#四分位距  ulim = Q3 + 1.5*IQR#上限 非異常范圍內的最大值  llim = Q1 - 1.5*IQR#下限 非異常范圍內的最小值  # llim = 0 if llim < 0 else llim  # out_list = [llim,Q1,Q2,Q3,ulim]  # 統計異常點個數  # 正常數據列表  right_list = []  Error_Point_num = 0  value_total = 0  average_num = 0  for item in input_list:    if item < llim or item > ulim:      Error_Point_num += 1    else:      right_list.append(item)      value_total += item      average_num += 1  average_value = value_total/average_num  # 特征值保留一位小數  out_list = [average_value,min(right_list), Q1, Q2, Q3, max(right_list)]  # print(out_list)  out_list = Save1point(out_list)  return out_list,Error_Point_num
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 大关县| 胶州市| 新津县| 大同县| 三江| 阳城县| 鹤山市| 沂水县| 成都市| 大埔县| 赣州市| 高青县| 中西区| 柞水县| 本溪| 海南省| 长岛县| 和田县| 荆州市| 澜沧| 原平市| 中方县| 大埔区| 西贡区| 凉山| 梨树县| 德州市| 东山县| 福清市| 图们市| 庐江县| 彰化县| 黄骅市| 林甸县| 新巴尔虎左旗| 客服| 郸城县| 汉阴县| 长岛县| 清远市| 安多县|