import matplotlib.pyplot as plt
x = [1.2,1.3,2.1,3.2,5.1]
# 设置组距
distance = 1
# 计算组数
group_num = int((max(x) - min(x)) / distance)
# 绘制直方图
plt.hist(x, bins=group_num,rwidth = 0.8)
# 添加x, y轴描述信息
plt.xlabel("x")
plt.ylabel("y")
# 显示图像
plt.show()
效果:
*先得到纵坐标,用柱状图的方式绘制等间距坐标不等组局图
import matplotlib.pyplot as plt
import numpy as np
x = [1.2,1.3,2.1,3.2,5.1]
bins = [0,1,4,10]
# 得到每组频数
y = np.histogram(x, bins=bins)[0]
# 绘制柱状图
plt.bar([1,3,5],y,width=1.8)
# 分别设置坐标(控制等距)和坐标处写的标签
icks([0,2,4,6],['0','1','4','6'])
plt.show()
效果:
本文发布于:2024-02-05 05:40:40,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170725404363513.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |