各年级男女生人数条形统计图

mport numpy as npfrom matplotlib import pyplot as pltplt.figure(3)plt.rc('font', family='simhei', size=15) # 设置中文显示,字体大小plt.rc('axes', unicode_minus=False) # 该参数解决负号显示的问题c = ['大一', '大二', '大三', '大四'] # x轴刻度标记x = np.arange(len(c))*0.8 # x轴刻度数,条形基座中间x位置数g = [134, 132, 137, 135] # 条形图高度b = [232, 131, 138, 140]g1 = plt.bar(x=x, height=g, width=0.2, bottom=None, alpha=0.8, color='red', label="girl", \ align='edge', data=None)"""x: x轴坐标(元组、列表、数组);height:条形图高度;width: 条形图宽度bottom:设置条形基座的y坐标;align: 'center'基座在x位置,'edge'基座左边缘在x位置alpha:条形图透明度;color:条形图颜色;label:条形图标签"""b1 = plt.bar([x1+0.2 for x1 in x], height=b, width=0.2, alpha=0.8, color='blue', label="boy", align='edge')"""[x1+0.2 for x1 in x]:for x1 in range(len(x)): x[x1] += 1"""plt.title('各年级人数统计')plt.legend() # 显示图例plt.ylim(0, 300) # y轴刻度范围plt.ylabel('人数') # y轴标签plt.xticks([index + 0.2 for index in x], c) # 显示条形图的标签plt.xlabel('班级') # x轴标签# 在每一个条形图的顶部设置顶值for r1 in g1: height = r1.get_height() plt.text(r1.get_x()+r1.get_width()/2, height+1, str(height), ha="center", va="bottom")for r2 in b1: height = r2.get_height() plt.text(r2.get_x()+r2.get_width()/2, height+1, str(height), ha="center", va="bottom")plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值