Guest User

Untitled

a guest
Jul 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.22 KB | None | 0 0
  1. smdt = {'OSS': (24, 26, 24, 30, 30, 30, 29, 29, 32, 31, 34, 33, 36, 34), 'GVS': (41, 45, 37, 60, 46, 46, 41, 33, 43, 40, 46, 48, 54, 48), 'ATS': (99, 97, 0, 93, 82, 97, 99, 100, 100, 99, 100, 100, 100, 0), 'POSS': (42, 41, 38, 46, 46, 34, 28, 28, 58, 58, 69, 67, 71, 83), 'TS': (72, 80, 35, 77, 62, 60, 60, 49, 72, 72, 76, 70, 82, 77), 'RS': (27, 30, 32, 33, 29, 29, 25, 25, 26, 25, 29, 33, 38, 34)}
  2. params = {
  3. 'font.size' : 12,
  4. 'font.family' : 'Calibri',
  5. 'text.color':'dimgrey',
  6. 'xtick.color':'dimgrey',
  7. 'xtick.labelsize':12,
  8. 'ytick.labelsize':12,
  9. 'ytick.color':'dimgrey',
  10. 'lines.linewidth':0.5,
  11. 'legend.fontsize':10,
  12. 'axes.labelcolor':'dimgray'
  13. }
  14.  
  15. plt.rcParams.update(params)
  16.  
  17. fig = plt.figure() # Create matplotlib figure
  18. ax = fig.add_subplot(111) # Create matplotlib axes
  19. fig.set_size_inches(8, 3.5)
  20. ind = np.arange(14)
  21.  
  22. width = 0.16 #18
  23. width1 = 0.10
  24. avg_bar1 = smdt['OSS'] # (10,20,30,60)
  25. avg_bar2 = smdt['ATS'] #(20,26,31,31)
  26. avg_bar3 = smdt['POSS'] #(30,38,38,39)
  27. avg_bar4 = smdt['TS'] #(40,25,25,28)
  28. avg_bar5 = smdt['RS']#(40,55,35,45)
  29. avg_bar6 = smdt['GVS']
  30. print ind - 2*width
  31. rects1 = plt.bar(ind - 2*width, avg_bar1, width=width1, color='#367588',label='bar1', align = 'center')
  32. rects2 = plt.bar(ind - 1*width, avg_bar2, width=width1, color='#FFBB00', label='bar2', align = 'center')
  33. rects3 = plt.bar(ind + 0*width, avg_bar3, width=width1, color='#b2b2b2', label='bar3', align = 'center')
  34. rects4 = plt.bar(ind + 1*width, avg_bar4, width=width1, color='#f87b02', label='bar4', align = 'center')
  35. rects5 = plt.bar(ind + 2*width, avg_bar5, width=width1, color='#2f86ff', label='bar5', align = 'center')
  36. high_point_x = []
  37. high_point_y = []
  38.  
  39.  
  40. for i in range(0,13):
  41. single_bar_group={rects1[i].get_height():rects1[i].get_x() + rects1[i].get_width()/2.0,
  42. rects2[i].get_height():rects2[i].get_x() + rects2[i].get_width()/2.0,
  43. rects3[i].get_height():rects3[i].get_x() + rects3[i].get_width()/2.0,
  44. rects4[i].get_height():rects4[i].get_x()+rects4[i].get_width()/2.0,
  45. rects5[i].get_height():rects5[i].get_x() +rects5[i].get_width()/2.0}
  46. height_list = list(single_bar_group.keys())
  47. height_list.sort(reverse=True)
  48. total=int(rects1[i].get_height())+int(rects2[i].get_height())+int(rects3[i].get_height())+int(rects4[i].get_height())+ int( rects5[i].get_height())
  49. for single_height in height_list:
  50. high_point_y.append(total/5)
  51. all_heights = single_bar_group.keys()
  52. med = np.median(all_heights)
  53. numb = find_nearest(all_heights, med)
  54. high_point_x.append(single_bar_group[numb])
  55. break
  56.  
  57. ax.spines['right'].set_visible(False)
  58. ax.spines['left'].set_visible(False)
  59. ax.spines['top'].set_visible(False)
  60. ax.spines['bottom'].set_visible(False)
  61. remove_tick_param(ax)
  62. plt.xlim(-0.55,len(cat))
  63.  
  64.  
  65. ax.tick_params(axis='both', which='both', length=0)
  66. format_per(ax, 'yaxis', '%')
  67. ax2 = ax.twinx()
  68. # trend_line =ax2.plot(high_point_x,smdt['Glance Views Share'],color='#7cb85e',label='Glance View',linewidth=2)
  69. #print ind
  70. plt.xticks(ind, cat)
  71. ax2.spines['right'].set_visible(False)
  72. ax2.spines['left'].set_visible(False)
  73. ax2.spines['top'].set_visible(False)
  74. ax2.spines['bottom'].set_visible(False)
  75. remove_tick_param(ax2)
  76. ax2.set_xticklabels([]) # turn off x ticks
  77.  
  78. format_per(ax2, 'yaxis', '%')
  79. lst =cat #('Q1 2017', 'Q2 2017', 'Q3 2017', 'Q4 2017')
  80. colLabels = sorted(lst)
  81.  
  82.  
  83. fig.subplots_adjust(bottom=0.17) # making some room for the table
  84. cell_text = []
  85.  
  86. colors = [["#4285F4","w","w","w" ,"w"],[ "#FFBB00","w","w","w","w" ], ["#b2b2b2","w","w","w" ,"w"], ["#f87b02","w","w","w" ,"w"], ["#2f86ff","w","w","w","w"],["#7cb85e","w","w","w","w"] ]
  87.  
  88. cell_text.append(list(avg_bar1))
  89. cell_text.append(list(avg_bar2))
  90. cell_text.append(list(avg_bar3))
  91. cell_text.append(list(avg_bar4))
  92. cell_text.append(list(avg_bar5))
  93. cell_text.append(list(avg_bar6))
  94. rows = ['%s' % x for x in ('OSS', 'ATS', 'POSS','TS','RS', 'GVS')]
  95.  
  96. #plt.legend( loc="lower center",bbox_to_anchor=[0.5, -0.1],
  97. # bbox_transform=fig.transFigure, ncol=3)
  98.  
  99.  
  100. the_table = ax.table(cellText=cell_text, colLabels=colLabels,
  101. rowLabels=rows,cellLoc='center')#, bbox=[0, -0.27, 1,
  102. # the_table._cells[(1, -1 )].set_facecolor('#4285F4')
  103. the_table._cells[(1, -1 )].set_width(0.1) #_text.set_color('#4285F4')
  104. # for x in the_table._cells:
  105. # the_table._cells[x].set_width(0.1)
  106.  
  107.  
  108. the_table.add_cell(1,-2, 0.1,0.065).set_facecolor('#367588')
  109. the_table.add_cell(2,-2, 0.1,0.065).set_facecolor('#FFBB00')
  110. the_table.add_cell(3,-2, 0.1,0.065).set_facecolor('#b2b2b2')
  111. the_table.add_cell(4,-2, 0.1,0.065).set_facecolor('#f87b02')
  112. the_table.add_cell(5,-2, 0.1,0.065).set_facecolor('#2f86ff')
  113. the_table.add_cell(6,-2, 0.1,0.065).set_facecolor('#7cb85e')
  114. for cell in the_table._cells:
  115. the_table._cells[cell].set_linewidth(0.5)
  116.  
  117.  
  118. img_path = str(str('eleventh')+str(uuid)+str(slide_id)+'.png')
  119. plt.savefig(img_path, bbox_inches="tight", pad_inches=0
Add Comment
Please, Sign In to add comment