#最小值160,最大值189,
height =[160,163,175,180,176,177,168,189,188,177,174,170,173,181]#求组数
ma =max(height)
mi =min(height)
b =1
bi =int((ma - mi)/b)
plt.hist(height,bins = bi,density=True)#标签
plt.xlabel('区间')
plt.ylabel('频数、频率')
plt.title('身高直方图')
plt.show()
练习2
x =[random.randint(0,10)for i inrange(120)]
y =[random.randint(0,10)for i inrange(120)]
x1 =[random.randint(0,10)for i inrange(120)]
y1 =[random.randint(0,10)for i inrange(120)]
x2 =[random.randint(0,10)for i inrange(120)]
y2 =[random.randint(0,10)for i inrange(120)]
plt.figure(figsize=(12,10))
ax1=plt.subplot2grid((5,5),(0,0),colspan=4,rowspan=1)#第一个括号的(2,2)表示将画布分割成2*2,(0,0)表示该子图从位置(0,0)开始,colspan和rowspan分别表示子图占用的行长度和列长度
ax1.plot(x,y)
ax1.set_ylabel("1")
ax2=plt.subplot2grid((5,5),(1,0),colspan=4,rowspan=4)
ax2.plot(x1,y1)
ax2.set_ylabel("2")
ax3=plt.subplot2grid((5,5),(1,4),colspan=1,rowspan=4)
ax3.plot(x2,y2)
ax3.set_ylabel("3")
plt.savefig('例子2')
plt.show()