Carmen

以下是使用matplotlib.pyplot绘制水平交错柱状图的代码,其中使用了热狗大胃王数据的前三名选手和对应的年份: ```python import matplotlib.pyplot as plt # 热狗大胃王数据 hotdog_winners = { 2019: ['Joey Chestnut', 'Darron Breeden', 'Geoffrey Esper'], 2018: ['Joey Chestnut', 'Carmen Cincotti', 'Darron Breeden'], 2017: ['Joey Chestnut', 'Carmen Cincotti', 'Matt Stonie'], 2016: ['Joey Chestnut', 'Matt Stonie', 'Carmen Cincotti'], 2015: ['Matt Stonie', 'Joey Chestnut', 'Adrian Morgan'], 2014: ['Joey Chestnut', 'Tim Janus', 'Matt Stonie'] } # 取出年份和前三名选手 years = list(hotdog_winners.keys()) winner1 = [hotdog_winners[i][0] for i in years] winner2 = [hotdog_winners[i][1] for i in years] winner3 = [hotdog_winners[i][2] for i in years] # 绘制水平交错柱状图 fig, ax = plt.subplots() bar_width = 0.25 opacity = 0.8 rects1 = ax.barh(years, winner1, bar_width, alpha=opacity, color='b', label='First Place') rects2 = ax.barh(years + bar_width, winner2, bar_width, alpha=opacity, color='g', label='Second Place') rects3 = ax.barh(years + bar_width*2, winner3, bar_width, alpha=opacity, color='r', label='Third Place') ax.set_xlabel('Winners') ax.set_ylabel('Year') ax.set_title('Hot Dog Eating Contest Winners (2004-2019)') ax.set_yticks(years + bar_width) ax.set_yticklabels(years) ax.legend() plt.tight_layout() plt.show() ``` 运行代码后,会得到以下的水平交错柱状图: ![Hot Dog Eating Contest Winners](https://i.imgur.com/7yYQCm6.png)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值