matplotlib.pyplot.bar

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import numpy as np
import matplotlib.pyplot as plt

apples = np.array([91, 86, 23, 89, 45, 62, 39, 84, 88, 99, 21, 33])
oranges = np.array([94, 59, 23, 21, 36, 91, 26, 23, 12, 199, 33, 44])
plt.figure('Bar Chart', facecolor='lightgray')
plt.title('Bar Chart', fontsize=18)
plt.xlabel('Month', fontsize=16)
plt.ylabel('Volume', fontsize=16)
plt.tick_params(labelsize=10)
plt.grid(linestyle=':')
x = np.arange(1, 13)
plt.bar(x-0.2, apples, .4,color='dodgerblue', label='Apple')
plt.bar(x+0.2, oranges, .4,color='orangered', label='Orange')
# 修改x的刻度文本
plt.xticks(x, ['Jan', 'Feb', 'Mar', 'Apr',
'Mar', 'Jun', 'Jul', 'Aug',
'Sep', 'Oct', 'Nov', 'Dec'])
plt.legend()
plt.savefig('Bar.png')
plt.show()

out figure