python中matplotlib条形图数值大的在最底层显示_如何在matplotlib中设置条形图的大小...

本文展示了一张柱状图,该图表基于2014年的数据,对比了不同地区通过航空、陆地和海洋三种交通方式的到达人数。通过对每个区域的数据进行并排比较,突出了各种交通方式的重要性及其在各地区的分布情况。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

# Setting the positions and width for the barspos=list(range(len(df3['Air'])))width=0.25# Plotting the barsfig,ax=plt.subplots(figsize=(10,5))# Create a bar with pre_score data,# in position pos,plt.bar(pos,#using df['pre_score'] data,df3['Air'],# of widthwidth,# with alpha 0.5alpha=0.5,# with colorcolor='#EE3224',# with label the first value in first_namelabel=df3['Region'][0])# Create a bar with mid_score data,# in position pos + some width buffer,plt.bar([p+widthforpinpos],#using df['mid_score'] data,df3['Land'],# of widthwidth,# with alpha 0.5alpha=0.5,# with colorcolor='#F78F1E',# with label the second value in first_namelabel=df3['Region'][1])# Create a bar with post_score data,# in position pos + some width buffer,plt.bar([p+width*2forpinpos],#using df['post_score'] data,df3['Sea'],# of widthwidth,# with alpha 0.5alpha=0.5,# with colorcolor='#FFC222',# with label the third value in first_namelabel=df3['Region'][2])# Set the y axis labelax.set_ylabel('Arrival count')# Set the chart's titleax.set_title('Total arrival count by mode of transport by region in 2014')# Set the position of the x ticksax.set_xticks([p+1.5*widthforpinpos])# Set the labels for the x ticksax.set_xticklabels(df3['Region'])# Setting the x-axis and y-axis limitsplt.xlim(min(pos)-width,max(pos)+width*4)plt.ylim([0,max(df3['Air']+df3['Land']+df3['Sea'])])# Adding the legend and showing the plotplt.legend(['Air','Land','Sea'],loc='upper left')plt.grid()plt.show()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值