[英]How to make a bar chart on range of values on x-axis and count on the range on y-axis in python?
I have a list such as [0.2,0.4,1.2,2.4,5.4,6.0,0.3,3.4..]
and I want to group the values in the list to a range(interval can change for different inputs) 0-1
, 1-2
, 2-3
and would like to plot a graph where the x-axis is the range and y-axis depicts the no_of_values
in the given range?我有一个列表,例如
[0.2,0.4,1.2,2.4,5.4,6.0,0.3,3.4..]
并且我想将列表中的值分组到一个范围内(间隔可以针对不同的输入而改变) 0-1
, 1-2
, 2-3
并想绘制一个图表,其中 x 轴是范围,y 轴描绘给定范围内的no_of_values
?
For the above problem, {0-1:3,1-2:1,2-3:1,3-4:1,4-5:0,5-6:2}
对于上述问题,
{0-1:3,1-2:1,2-3:1,3-4:1,4-5:0,5-6:2}
Thanks in advance提前致谢
Try using pandas.DataFrame.hist尝试使用pandas.DataFrame.hist
pd.DataFrame(ls).hist()
where ls = [0.2,0.4,1.2,2.4,5.4,6.0,0.3,3.4]
其中
ls = [0.2,0.4,1.2,2.4,5.4,6.0,0.3,3.4]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.