前言:
如今兄弟们对“c语言计算奥运会比赛某个参赛选手的得分”大概比较注意,姐妹们都需要知道一些“c语言计算奥运会比赛某个参赛选手的得分”的相关文章。那么小编在网络上搜集了一些对于“c语言计算奥运会比赛某个参赛选手的得分””的相关资讯,希望同学们能喜欢,姐妹们快快来了解一下吧!例如我们要统计和国获取的金牌,银牌、铜牌的数据
统计主要参赛国家的奖牌数据,因此每个坐标上其实要画三个柱图,只不过每个柱图的篇移要重新计算。
import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltcountries = ['USA', 'GB', 'China', 'Russia', 'Germany']bronzes = np.array([38, 17, 26, 19, 15])silvers = np.array([37, 23, 18, 18, 10])golds = np.array([46, 27, 26, 19, 17])ind = [x for x, _ in enumerate(countries)]plt.bar(ind, golds, width=0.8, label='golds', color='gold', bottom=silvers+bronzes)plt.bar(ind, silvers, width=0.8, label='silvers', color='silver', bottom=bronzes)plt.bar(ind, bronzes, width=0.8, label='bronzes', color='#CD853F') plt.xticks(ind, countries)plt.ylabel("Medals")plt.xlabel("Countries")plt.legend(loc="upper right")plt.title("2012 Scorers")plt.show()
构造奖牌数据
bronzes = np.array([38, 17, 26, 19, 15])silvers = np.array([37, 23, 18, 18, 10])golds = np.array([46, 27, 26, 19, 17])
计算底部偏 移量 bottomc参数实际等于前面两个奖牌的数据之和,依此类推
plt.bar(ind, golds, width=0.8, label='golds', color='gold', bottom=silvers+bronzes)
plt.bar(ind, silvers, width=0.8, label='silvers', color='silver', bottom=bronzes)
如何将X方向的刻度 显示为标题
plt.xticks(ind, countries)
仔细发现横向,纵向的标签字体有点小,修改一下
对比一下label的字体大小
'''Created on 2023年1月2日@author: admin'''import numpy as npimport matplotlib as mplimport matplotlib.pyplot as pltcountries = ['USA', 'GB', 'China', 'Russia', 'Germany']bronzes = np.array([38, 17, 26, 19, 15])silvers = np.array([37, 23, 18, 18, 10])golds = np.array([46, 27, 26, 19, 17])ind = [x for x, _ in enumerate(countries)]plt.bar(ind, golds, width=0.8, label='golds', color='gold', bottom=silvers+bronzes)plt.bar(ind, silvers, width=0.8, label='silvers', color='silver', bottom=bronzes)plt.bar(ind, bronzes, width=0.8, label='bronzes', color='#CD853F')font2 = {'family' : 'Times New Roman', 'weight' : 'normal', 'size' : 28,}plt.xticks(ind, countries)plt.ylabel("Medals",font2)plt.xlabel("Countries",font2)plt.legend(loc="upper right")plt.title("2012 Scorers")plt.show()
最后是运行视频
视频加载中...
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #c语言计算奥运会比赛某个参赛选手的得分