matplot python在直方图中缺少最后一个bin [英] missing last bin in histogram plot from matplot python

查看:28
本文介绍了matplot python在直方图中缺少最后一个bin的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据自己的价值绘制直方图

I'm trying to draw histrogram based of my value

x = ['3', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5',
     '2', '3', '4', '5', '6', '4', '2', '0', '1', '9', '8', 
     '8', '8', '8', '8', '9', '3', '8', '0', '9', '5', '2',
     '5', '7', '2', '0', '1', '0', '6', '5']
x_num = [int(i) for i in x]

key = '0123456789'
for i in key:
    print(i," count =>",x.count(i))

plt.hist(x_num, bins=[0,1,2,3,4,5,6,7,8,9])

最后2个数字"8、9"箱应具有6、4的分配计数但是在直方图中,它结合了 8 和 9 并获得了 10 的值,而不是将它们分开.bin 的总数应该是 10 => 但它只给我 9 的图 ..

The last 2 numbers "8, 9" bin should have distribution count of 6 , 4 But in histogram it combine 8 and 9 and get value of 10 instead of separate them. Total number of bin should be 10 => but it only giving me graph of 9..

我该如何将它们分开并破坏8和9?

How could I separate them and break 8 and 9 ?

推荐答案

import matplotlib.pyplot as plt


x = ['3', '1', '4', '1', '5', '9', '2', '6', '5', '3', '5',
     '2', '3', '4', '5', '6', '4', '2', '0', '1', '9', '8',
     '8', '8', '8', '8', '9', '3', '8', '0', '9', '5', '2',
     '5', '7', '2', '0', '1', '0', '6', '5']
x_num = [int(i) for i in x]

key = '0123456789'
for i in key:
    print(i, " count =>", x.count(i))

plt.hist(x_num, bins=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10])
plt.show()

这篇关于matplot python在直方图中缺少最后一个bin的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆