-
Notifications
You must be signed in to change notification settings - Fork 0
/
PYTHON_PLT_HIST.py
32 lines (25 loc) · 1.12 KB
/
PYTHON_PLT_HIST.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
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({'CLASS_TYPES': ['A','A','A','B','B',
'C','C','C','D','E',
'E','F','F','F','F',
'G','G','G','G','G']})
fig = plt.figure()
ax = fig.add_axes([0,0,1.5,1.5])
classTypes = ['A','B','C','D','E','F','G']
classCount = [len(df[df.CLASS_TYPES == 'A']),
len(df[df.CLASS_TYPES == 'B']),
len(df[df.CLASS_TYPES == 'C']),
len(df[df.CLASS_TYPES == 'D']),
len(df[df.CLASS_TYPES == 'E']),
len(df[df.CLASS_TYPES == 'F']),
len(df[df.CLASS_TYPES == 'G'])]
ax.bar(classTypes,classCount,color=['#ffadad', '#ffd6a5', '#fdffb6', '#caffbf', '#ffc6ff','#9bf6ff','#a0c4ff'])
for x,y in zip(classTypes,classCount):
label = "{:.2f}".format(y)
plt.annotate(label, # label text
(x,y), # The point (x, y) to annotate
textcoords="offset points", # offset (in points) from the xy value
xytext=(0,10), # position (x, y) to place the text at.
ha='center') # horizontal alignment is center in this case
plt.show()