如何修复关于外观的直方图并删除empyes?

2024-03-28 14:51:54 发布

您现在位置:Python中文网/ 问答频道 /正文

我有数据,例如,A。 A的平均值为50.966771,最小值和最大值分别为0.0、19955.1

我需要做柱状图,我做了,但它没有显示好,我如何修复,为什么它们像正方形,它们没有起伏,柱状图正常吗,为什么它们有空的地方,如何修复

我的密码是:

import matplotlib.pyplot as plt
fig = plt.figure(figsize= (35,15))
plt.style.use('ggplot')

plt.subplot(421)
plt.hist(df_3['adrenal gland'], color = 'blue', bins = 5, density = True)
plt.title("A",size =30)

enter image description here


1条回答
网友
1楼 · 发布于 2024-03-28 14:51:54

正如我在评论中问你的那样

df_3['adrenal gland'].quantile([0,.25, .5,.75,1])

你回答说结果是正确的

0.00 0.00
0.25 0.10
0.50 3.80
0.75 24.05
1.00 19955.10

25%的数据低于0.10的值

50%的数据低于3.8的值(中位数)

75%的数据低于24.05的值

正如你在问题中提到的,那么平均值是50

您有影响直方图形状的极值,因此删除这些极值,您将得到预期的直方图

试一试

extreme_values=1000 # for example
plt.hist(df_3[df_3['adrenal gland']<extreme_values]['adrenal gland'], color = 'blue', bins = 100, density = True)

你会发现这是一个倾斜的直方图

相关问题 更多 >