简体   繁体   English

python - 如何在x轴上的值范围上制作条形图并计算y轴上的范围?

[英]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-11-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.

相关问题 如何更改matlibplot中x轴和y轴的范围? - How to change the range of the x-axis and y-axis in matlibplot? 堆叠条形图交换 x 轴和 y 轴 - Stacked bar chart swap x-axis and y-axis 有没有办法用 plotly 或 python 创建条形图可视化,其中 y 轴是 24 小时范围,x 轴是所有工作日? - Is there a way to create a bar graph visualization with plotly or python where the y-axis is 24hour range and x-axis is all the weekdays? 具有标称/分类x轴+双y轴的Python散景条形图 - Python bokeh bar chart with nominal / categorical x-axis + twin y-axis 如何使用 matplotlib.pyplot 在 x 轴上创建分组条形图(按月和年)并在 y 轴上创建值? - How to create a grouped bar chart (by month and year) on the x-axis and values on the y-axis using matplotlib.pyplot? 如何用pyplot在相同的x轴(日期时间)但不同的y轴上绘制线形图和条形图? - How to plot line and bar-chart on the same x-axis (datetime) but different y-axis with pyplot? Altair - 将 y 轴与不同图表的 x 轴链接 - Altair - link y-axis with x-axis of a different chart 以次要y轴和x轴为日期的图表 - Chart with secondary y-axis and x-axis as dates 设置y轴标签,范围,条形图python的限制 - Setting y-axis labels, range, limit on bar graph python 在高级图表上设置x轴和y轴范围? - Setting x-axis and y-axis range on high-level charts?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM