如何使用 python 绘制一维数组以获得第 25、50 和 75 个百分位数

问题描述 投票:0回答:1

你好,我有一个数组

x = [9.904725629894529e-06, 1.2634955055546016e-05, 1.5201896530925296e-05, 2.9845547032891773e-05, 3.49247275153175e-05, 3.4970289561897516e-05, 4.780302697326988e-05, 4.802399416803382e-05, 4.810681639355607e-05, 4.843798524234444e-05, 4.859635737375356e-05, 5.9152505855308846e-05, 5.9193022025283426e-05, 5.9363908803788945e-05, 5.9468671679496765e-05, 6.630286952713504e-05, 7.005851512076333e-05, 7.014916627667844e-05, 8.021695248316973e-05, 8.989680645754561e-05, 9.008277265820652e-05, 9.028125350596383e-05, 9.037737618200481e-05, 9.04681728570722e-05, 9.083149052457884e-05, 0.00021005164308007807, 0.00021028853370808065, 0.00021039179409854114, 0.00021039319108240306, 0.00021107416250742972, 0.00021134318376425654, 0.00021135005226824433, 0.00021196113084442914, 0.00021199103503022343, 0.0002120915160048753, 0.0002126666222466156, 0.000213045728742145, 0.00021316968195606023, 0.00021321520034689456, 0.00021339277736842632, 0.00021368247689679265, 0.0002137374976882711, 0.00021400606783572584, 0.00021451167413033545, 0.00021501131413970143]

我想在 python 中绘制它以找到第 25 个、第 50 个和第 75 个百分位值。

我用过

plt.plot(x) plt.show()
但分布看起来不像我们可以区分数字。

python matplotlib statistics visualization
1个回答
0
投票

您可以使用 numpy 获取数据的百分位数。以下内容来自百分位的文档

import numpy as np

# 1D array
arr = [20, 2, 7, 1, 34]
print("arr : ", arr)
print("50th percentile of arr : ",
      np.percentile(arr, 50))
print("25th percentile of arr : ",
      np.percentile(arr, 25))
print("75th percentile of arr : ",
      np.percentile(arr, 75))

输出:

arr :  [20, 2, 7, 1, 34]
50th percentile of arr :  7.0
25th percentile of arr :  2.0
75th percentile of arr :  20.0
© www.soinside.com 2019 - 2024. All rights reserved.