本篇文章為大家展示了使用Python怎么繪制雙柱狀圖并顯示數(shù)值,內(nèi)容簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細介紹希望你能有所收獲。
具體如下:
# -*- coding:utf-8 -*- #! python3 import matplotlib.pyplot as plt import mpl_toolkits.mplot3d #定義函數(shù)來顯示柱狀上的數(shù)值 def autolabel(rects): for rect in rects: height = rect.get_height() plt.text(rect.get_x()+rect.get_width()/2.-0.2, 1.03*height, '%s' % float(height)) if __name__ == '__main__': l1=[68, 96, 85, 86, 76,87, 95] l2=[85, 68, 79, 89, 94, 82,90] name=['A','B','C','D','E','F','E'] total_width, n = 0.8, 2 width = total_width / n x=[0,1,2,3,4,5,6] plt.rc('font', family='SimHei', size=12)#設(shè)置中文顯示,否則出現(xiàn)亂碼! a=plt.bar(x, l1, width=width, label='數(shù)學(xué)',fc = 'y') for i in range(len(x)): x[i] = x[i] + width b=plt.bar(x, l2, width=width, label='語文',tick_label = name,fc = 'r') autolabel(a) autolabel(b) plt.xlabel('學(xué)生') plt.ylabel('成績') plt.title('學(xué)生成績') plt.legend() plt.show()
運行結(jié)果:
上述內(nèi)容就是使用Python怎么繪制雙柱狀圖并顯示數(shù)值,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享題目:使用Python怎么繪制雙柱狀圖并顯示數(shù)值-創(chuàng)新互聯(lián)
文章源于:http://muchs.cn/article14/dgcide.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站維護、移動網(wǎng)站建設(shè)、網(wǎng)站導(dǎo)航、網(wǎng)站設(shè)計公司、App設(shè)計、用戶體驗
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容