matplotlib柱狀圖


 1 import numpy as np
 2 import matplotlib.pyplot as plt
 3 size = 5
 4 a = np.random.random(size)
 5 b = np.random.random(size)
 6 c = np.random.random(size)
 7 d = np.random.random(size)
 8 x = np.arange(size)
 9 
10 total_width, n = 0.8, 3     # 有多少個類型,只需更改n即可
11 width = total_width / n
12 x = x - (total_width - width) / 2
13 
14 plt.bar(x, a,  width=width, label='a')
15 plt.bar(x + width, b, width=width, label='b')
16 plt.bar(x + 2 * width, c, width=width, label='c')
17 plt.legend()
18 plt.show()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM