python - matplotlib 中的直方图未正确分箱
问题描述
我正在尝试从一些自举数据创建直方图,但我的直方图没有正确分箱。它没有显示频率,而是将每个点绘制为自己的 bin。
每个点都是它自己的颜色,所以我不确定它是否将每个条目作为自己的系列。
这是我的代码:
import pip
import xlrd as xlrd
import numpy as np
import plotly.plotly as py
import plotly.graph_objs as go
import matplotlib
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import pandas as pd
from pandas import DataFrame
exams212 = pd.read_excel('212bare.xlsx')
df = DataFrame(exams212)
mc =df.query('Gender == "M" and Treatment == "C"')
mt =df.query('Gender == "M" and Treatment == "T"')
fc =df.query('Gender == "F" and Treatment == "C"')
ft=df.query('Gender == "F" and Treatment == "T"')
#MC averages
mcave = []
for x in range(10):
rows = mc.sample(n=381, replace=True)
mcavg=rows.mean()
mcave.append(mcavg)
print(mcave)
mcplot=plt.hist(mcave,bins=5)
plt.show(mcplot)
我最终会为更大的数字这样做,但我现在一直在玩十个,只是为了排除故障,试图强制 5 个垃圾箱,看看我是否可以让它做我想做的事。
我的打印结果如我所料:
[P212 EX1 0.73931
dtype: float64, P212 EX1 0.72205
dtype: float64, P212 EX1 0.71315
dtype: float64, P212 EX1 0.717682
dtype: float64, P212 EX1 0.730556
dtype: float64, P212 EX1 0.730562
dtype: float64, P212 EX1 0.726436
dtype: float64, P212 EX1 0.736711
dtype: float64, P212 EX1 0.749921
dtype: float64, P212 EX1 0.74974
dtype: float64]
但我得到的图看起来像这样,有 10 个 bin,每个数据点一个: histogram not binned
我错过了什么愚蠢的东西吗?我一直试图弄清楚这一点,但找不到任何东西。谢谢!
解决方案
推荐阅读
- .net - 通过编译为ast然后反编译来重组.net代码
- python - 使用 Boto 自动上传到 AWS S3 存储桶 Yields Expired Token Error
- python - 使用 Opencv 进行人脸检测
- firebase - 具有多个字段的 Firestore 分布式计数器
- node.js - 向 mongoDB 插入数据时显示 db 未定义
- python - 使硒无法检测的措施
- sql - Visual Studio SQL 返回重复值
- spring - java_options 中的第二个弹簧配置文件
- javascript - 为什么在 JavaScript 对象的 getter 和 setter 上使用 delete?
- javascript - 原生 JS 使用每个父类上的计数器重置添加类