import matplotlib.pyplot as plt
import numpy as np
x = np.array([-100, 12, 45, 30, 70, 36, 50, 40, 26, 38])
print(sorted(x))
a = np.quantile(x, 0.75) # 上四分之一数
b = np.quantile(x, 0.25) # 下四分之一数
print("平均数:", np.mean(x)) # 打印均值
print("中位数:", np.median(x)) # 打印中位数
print("上四分之一数:", a) # 打印上四分之一数
print("下四分之一数:", b) # 打印下四分之一数
up = a + 1.5 * (a - b) # 异常值判断标准
down = b - 1.5 * (a - b) # 异常值判断标准
x = np.sort(x) # 对原始数据排序
shangjie = x[x < up][-1] # 除了异常值外的最大值
xiajie = x[x > down][0] # 除了异常值外的最小值
print("上界:", shangjie) # 打印上界
print("up:", up)
print("down:", down)
print("下界:", xiajie) # 打印下界
plt.grid(True) # 显示网格
y = plt.boxplot(x, meanline=True, showmeans=True,
flierprops={"marker": "o", "markerfacecolor": "red", "markersize": 15}) # 绘制箱形图,设置异常点大小、样式等
plt.show() # 显示图
import matplotlib.pyplot as plt
import numpy as np
x = np.array([-100, 12, 45, 30, 70, 36, 50, 40, 26, 38])
print(sorted(x))
a = np.quantile(x, 0.75) # 上四分之一数
b = np.quantile(x, 0.25) # 下四分之一数
print("平均数:", np.mean(x)) # 打印均值
print("中位数:", np.median(x)) # 打印中位数
print("上四分之一数:", a) # 打印上四分之一数
print("下四分之一数:", b) # 打印下四分之一数
up = a + 1.5 * (a - b) # 异常值判断标准
down = b - 1.5 * (a - b) # 异常值判断标准
x = np.sort(x) # 对原始数据排序
shangjie = x[x < up][-1] # 除了异常值外的最大值
xiajie = x[x > down][0] # 除了异常值外的最小值
print("上界:", shangjie) # 打印上界
print("up:", up)
print("down:", down)
print("下界:", xiajie) # 打印下界
plt.grid(True) # 显示网格
y = plt.boxplot(x, meanline=True, showmeans=True,
flierprops={"marker": "o", "markerfacecolor": "red", "markersize": 15}) # 绘制箱形图,设置异常点大小、样式等
plt.show() # 显示图