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()

matplotlib柱状图

matplotlib柱状图

 

相关文章:

  • 2021-11-22
  • 2021-11-22
  • 2021-07-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-30
猜你喜欢
  • 2022-02-12
  • 2021-10-20
  • 2021-06-21
  • 2021-08-26
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
相关资源
相似解决方案