【发布时间】:2014-03-12 23:42:09
【问题描述】:
我正在尝试运行以下代码:
variable_values = #numpy vector, one dimension, 5053 values between 1 and 0.
label_values = #numpy vector, one dimension, 5053 values, discrete value of either 1 OR 0.
x = variable_values[variable_values != '?'].astype(float)
y = label_values[variable_values != '?'].astype(float)
print np.max(x) #prints 0.90101
print np.max(y) #prints 1.0
N = 5053
ind = np.arange(N) # the x locations for the groups
width = 0.45 # the width of the bars: can also be len(x) sequence
n, bins, patches = plt.hist(x, 5, stacked=True, normed = True)
#Stack the data
plt.figure()
plt.hist(x, bins, stacked=True, normed = True)
plt.hist(y, bins, stacked=True, normed = True)
plt.show()
我想要实现的是下图:
每个条上的颜色根据label 的值是1 还是0 进行拆分。
不幸的是,我目前的输出是:
这有两点不正确 - 首先它没有正确堆叠。其次,Y 轴上的值上升到 1.6,但我相信 Y 轴应该包含属于每个子组的数据条数(因此,如果所有数据条的值都在 0-0.25 之间,那么只有显示数据的栏将是第一个)。
【问题讨论】:
-
这是一个直方图。最高峰将是最频繁的值,而不是最大值。
-
@M4rtini 对不起,是的,你是对的 - 为什么这里最多打印 1.6?理想情况下,我喜欢将 5053 条数据分成四个条形(数据条数显示在 Y 轴上),并且条形按标签==1 和标签==0 的数字拆分。抱歉,我对自己的问题感到困惑。马上更新。
标签: python graph matplotlib plot scikit-learn