77import matplotlib
88import numpy as np
99import 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' ]
1213playerA = np .array ([5 , 15 , 22 , 20 , 25 ])
1314playerB = np .array ([25 , 32 , 34 , 30 , 27 ])
1415x = np .arange (len (labels ))
1516width = 0.35
16-
1717fig , ax = plt .subplots ()
1818rects1 = ax .bar (x - width / 2 , np .zeros_like (playerA ), width ,
1919 bottom = playerA , label = 'Player A' , fill = False )
2020rects2 = 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' )
2322# 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 )
2524ax .set_ylabel ('Score' )
2625ax .set_title ('Scores by number of game and Players' )
2726ax .set_xticks (x )
2827ax .set_xticklabels (labels )
2928ax .legend ()
3029ax .set_xlabel ('Games' )
31- #--------------------------------------------------------------------------------------------
32- def Label (heights ,rects ):
30+ def Label (heights , rects ):
3331 """Attach a text label on top of each bar. """
3432 i = 0
3533 for rect in rects :
@@ -40,8 +38,8 @@ def Label(heights,rects):
4038 xytext = (0 , 4 ), # 4 points vertical offset.
4139 textcoords = "offset points" ,
4240 ha = 'center' , va = 'bottom' )
43- Label (playerA ,rects1 )
44- Label (playerB ,rects2 )
41+ Label (playerA , rects1 )
42+ Label (playerB , rects2 )
4543fig .tight_layout ()
4644plt .show ()
4745#############################################################################
0 commit comments