7
7
import matplotlib
8
8
import numpy as np
9
9
import matplotlib .pyplot as plt
10
- # initialise labels and a numpy array make sure you have N labels of N number of values in the array
11
- labels = ['I' , 'II' ,'III' ,'IV' ,'V' ]
10
+ # initialise labels and a numpy array make sure you have
11
+ # N labels of N number of values in the array
12
+ labels = ['I' , 'II' , 'III' , 'IV' , 'V' ]
12
13
playerA = np .array ([5 , 15 , 22 , 20 , 25 ])
13
14
playerB = np .array ([25 , 32 , 34 , 30 , 27 ])
14
15
x = np .arange (len (labels ))
15
16
width = 0.35
16
-
17
17
fig , ax = plt .subplots ()
18
18
rects1 = ax .bar (x - width / 2 , np .zeros_like (playerA ), width ,
19
19
bottom = playerA , label = 'Player A' , fill = False )
20
20
rects2 = ax .bar (x + width / 2 , playerB - playerA , width ,
21
- bottom = playerA , label = 'Player B' ,edgecolor = 'black' )
22
- #-----------------------------------------------------------------------------------------
21
+ bottom = playerA , label = 'Player B' , edgecolor = 'black' )
23
22
# Add some text for labels, title and custom x-axis tick labels, etc.
24
- ax .set_ylim (0 ,60 )
23
+ ax .set_ylim (0 , 60 )
25
24
ax .set_ylabel ('Score' )
26
25
ax .set_title ('Scores by number of game and Players' )
27
26
ax .set_xticks (x )
28
27
ax .set_xticklabels (labels )
29
28
ax .legend ()
30
29
ax .set_xlabel ('Games' )
31
- #--------------------------------------------------------------------------------------------
32
- def Label (heights ,rects ):
30
+ def Label (heights , rects ):
33
31
"""Attach a text label on top of each bar. """
34
32
i = 0
35
33
for rect in rects :
@@ -40,8 +38,8 @@ def Label(heights,rects):
40
38
xytext = (0 , 4 ), # 4 points vertical offset.
41
39
textcoords = "offset points" ,
42
40
ha = 'center' , va = 'bottom' )
43
- Label (playerA ,rects1 )
44
- Label (playerB ,rects2 )
41
+ Label (playerA , rects1 )
42
+ Label (playerB , rects2 )
45
43
fig .tight_layout ()
46
44
plt .show ()
47
45
#############################################################################
0 commit comments