-
Notifications
You must be signed in to change notification settings - Fork 0
/
PYTHON_PLT_HIST_B.py
52 lines (36 loc) · 1.38 KB
/
PYTHON_PLT_HIST_B.py
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import matplotlib.pyplot as plt
import pandas as pd
d = {'CLASS_TYPE': ['A','B','C','D','E'], 'MEN': [20,25,30,19,38], 'WOMEN': [21,31,55,22,39]}
df = pd.DataFrame(data=d)
classType = df["CLASS_TYPE"]
men_count = df["MEN"]
women_count = df["WOMEN"]
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
ax = fig.add_axes([0,0,1.5,1.5])
ax.bar(classType, men_count, width, label='Men')
ax.bar(classType , women_count, width, bottom=men_count, label='Women')
ax.set_ylabel('Count')
ax.set_xlabel('Classes')
ax.set_title('Count of Classes By Gender')
ax.legend()
for x,y1,y2 in zip(classType,women_count,men_count):
label = "{:.2f}".format(y1)
plt.annotate(label, # label text
(x,y1), # The point (x, y) to annotate
textcoords="offset points", # offset (in points) from the xy value
xytext=(0,6), # position (x, y) to place the text at.
ha='center') # horizontal alignment is center in this case
label = "{:.2f}".format(y2)
plt.annotate(label,
(x,y2),
textcoords="offset points",
xytext=(0,-14),
ha='center')
label = "{:.2f}".format(y1+y2)
plt.annotate(label,
(x,y1+y2),
textcoords="offset points",
xytext=(0,9),
ha='center')
plt.show()