本篇文章為大家展示了使用Python怎么繪制雙柱狀圖并顯示數(shù)值,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
具體如下:
# -*- coding:utf-8 -*- #! python3 import matplotlib.pyplot as plt import mpl_toolkits.mplot3d #定義函數(shù)來(lái)顯示柱狀上的數(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='語(yǔ)文',tick_label = name,fc = 'r') autolabel(a) autolabel(b) plt.xlabel('學(xué)生') plt.ylabel('成績(jī)') plt.title('學(xué)生成績(jī)') plt.legend() plt.show()
運(yùn)行結(jié)果:
上述內(nèi)容就是使用Python怎么繪制雙柱狀圖并顯示數(shù)值,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注億速云行業(yè)資訊頻道。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。