1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
| import matplotlib.pyplot as plt
import numpy as np
data_man = [120, 200, 150, 80, 70, 110, 130]
data_woman = [100, 50, 90, 50, 80, 30, 30]
x = np.arange(len(data))
bar1 = plt.bar(
x,
data_man,
label='Man',
color='#009392',
)
bar2 = plt.bar(
x,
data_woman,
bottom=data_man,
label='Woman',
color='#cf5974',
)
plt.bar_label(
bar1,
label_type='center',
labels=data_man, # 设置显示的值
)
plt.bar_label(
bar2,
label_type='center',
labels=data_woman,
)
plt.xticks(
x,
['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
)
plt.legend()
|