我有一个如下所示的数据帧:
Edades
0 -15.612896
1 -18.612896
2 11.387104
3 -12.612896
4 17.387104
...
566597 15.387104
566598 5.387104
566599 6.387104
566600 0.387104
566601 22.387104
我想做一个条形图,显示按照标准偏差倍数定义的区间分类的数据频率。到目前为止,我知道plt.hist()
实际上可以做类似的事情,但它不允许我在范围上使用浮点类型的值
我尝试的代码如下所示:
plt.figure("Edad_Distrib")
plt.hist(nuevo_edad, range(-100,100))
plt.xlabel("Edades")
plt.ylabel("Frecuencia")
plt.title("Distrib edades")
plt.show()
如何在这样的范围内绘制某个对象
plt.hist(nuevo_edad, range(-2*stdev,2*stdev))
如果它有任何用途的话,我有一段代码,我的教授在R中做的代码,这段代码就是用随机生成的数据帧实现的,我只是不知道如何用python和我特定的数据帧实现它
A <- rnorm(100)
m <- mean(A)
s <- var(A)
k <- -11
x = seq(-5, 5, length = k)
y = vector("numeric", length = (k-1))
for (i in 1:(k-1)){
y[i] = sum(A>x[i] & A<x[i+1])
}
barplot(y)
df.a.mean() ± df.a.std() * value
定义箱子边缘如果要定义一个范围,最常用的方法是将其传递给函数作为keyword argument(
kwarg
),在本例中为range
。它将是这样的:请注意,您不会传递集合(作为
range(a, b)
)。在hist
中的参数range
是两个元素的元组PS:这只影响要绘制的数据。如果您不是指直方图中需要多少条,请使用参数
bins
例如:
这将绘制分布在20条中的
-2*stdev
和2*stdev
之间的所有数据相关问题 更多 >
编程相关推荐