Advertisement
Guest User

it keeps on going

a guest
Mar 19th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.61 KB | None | 0 0
  1. import numpy as np
  2. from scipy.stats import wilcoxon
  3.  
  4.  
  5. def array_to_percentages(l):
  6.   l_sum = 0
  7.   for i in l:
  8.     l_sum += i
  9.  
  10.   return (np.true_divide(l[0], l_sum) * 100.0, np.true_divide(l[1], l_sum) * 100.0, np.true_divide(l[2], l_sum) * 100.0, np.true_divide(l[3], l_sum) * 100.0, np.true_divide(l[4], l_sum) * 100.0)
  11.  
  12. c1_f_comfort = [0,3,3,14,14]
  13. c1_s_comfort = [8,16,6,3,1]
  14. c2_f_comfort = [2,4,3,16,9]
  15. c2_s_comfort = [18,8,2,4,2]
  16. c3_f_comfort = [0,2,5,15,12]
  17. c3_s_comfort = [12,11,7,3,1]
  18. c4_f_comfort = [0,4,5,14,11]
  19. c4_s_comfort = [16,7,6,2,3]
  20.  
  21. c1_friend = [3,1,4,4,4,4,4,2,3,4,3,3,1,3,4,3,1,3,3,4,3,4,4,2,3,4,3,3,4,3,3,4,2,4]
  22. c1_stranger = [2,0,0,4,1,1,3,0,2,0,1,3,0,1,2,1,0,1,1,2,1,2,2,1,1,1,1,0,0,1,3,1,1,1]
  23. c2_friend = [3,3,3,4,4,3,4,1,3,3,3,3,1,2,4,3,0,3,4,4,3,4,3,1,2,1,3,3,4,3,3,4,2,0]
  24. c2_stranger = [0,1,0,4,1,1,3,0,1,3,0,3,0,0,2,0,0,0,0,1,0,1,2,0,0,0,0,4,0,1,3,0,1,0]
  25. c3_friend = [3,3,4,4,4,3,4,2,3,2,4,3,1,3,4,3,3,2,4,3,3,4,3,2,4,1,3,3,4,3,3,4,2,4]
  26. c3_stranger = [1,0,0,4,0,0,3,1,1,2,1,3,0,0,2,1,2,0,2,1,0,2,2,1,0,0,1,0,1,0,3,2,1,1]
  27. c4_friend = [3,3,4,4,4,3,4,1,3,2,3,3,1,3,4,3,2,3,4,4,3,4,3,2,3,1,4,2,4,4,3,3,2,1]
  28. c4_stranger = [0,0,0,4,0,0,4,0,1,2,1,3,0,1,2,0,0,0,1,2,0,1,2,1,0,0,0,4,2,0,3,0,1,2]
  29.  
  30. test_dict = {}
  31. test_dict["c1_friend"] = [3, 1, 4, 4, 4, 4, 4, 2, 3, 4, 3, 3, 1, 3, 4, 3, 1, 3, 3, 4, 3, 4, 4 ,2, 3, 4, 3, 3, 4, 3, 3, 4, 2, 4]
  32. test_dict["c1_stranger"] = [2, 0, 0, 4, 1, 1, 3, 0, 2, 0, 1, 3, 0, 1, 2, 1, 0, 1, 1, 2, 1, 2, 2, 1, 1, 1, 1, 0, 0, 1, 3, 1, 1, 1]
  33. test_dict["c2_friend"] = [3,3,3,4,4,3,4,1,3,3,3,3,1,2,4,3,0,3,4,4,3,4,3,1,2,1,3,3,4,3,3,4,2,0]
  34. test_dict["c2_stranger"] = [0,1,0,4,1,1,3,0,1,3,0,3,0,0,2,0,0,0,0,1,0,1,2,0,0,0,0,4,0,1,3,0,1,0]
  35. test_dict["c3_friend"] = [3,3,4,4,4,3,4,2,3,2,4,3,1,3,4,3,3,2,4,3,3,4,3,2,4,1,3,3,4,3,3,4,2,4]
  36. test_dict["c3_stranger"] = [1,0,0,4,0,0,3,1,1,2,1,3,0,0,2,1,2,0,2,1,0,2,2,1,0,0,1,0,1,0,3,2,1,1]
  37. test_dict["c4_friend"] = [3,3,4,4,4,3,4,1,3,2,3,3,1,3,4,3,2,3,4,4,3,4,3,2,3,1,4,2,4,4,3,3,2,1]
  38. test_dict["c4_stranger"] = [0,0,0,4,0,0,4,0,1,2,1,3,0,1,2,0,0,0,1,2,0,1,2,1,0,0,0,4,2,0,3,0,1,2]
  39.  
  40. count_dict = {}
  41. count_dict["c1_friend"] = [0,3,3,14,14]
  42. count_dict["c1_stranger"] = [8,16,6,3,1]
  43. count_dict["c2_friend"] = [2,4,3,16,9]
  44. count_dict["c2_stranger"] = [18,8,2,4,2]
  45. count_dict["c3_friend"] = [0,2,5,15,12]
  46. count_dict["c3_stranger"] = [12,11,7,3,1]
  47. count_dict["c4_friend"] = [0,4,5,14,11]
  48. count_dict["c4_stranger"] = [16,7,6,2,3]
  49.  
  50. key_len = len( list(test_dict.keys()) )
  51.  
  52. # String slice to get the desired results
  53. # Compare the samples
  54. i = 0
  55.  
  56. while i < key_len:
  57.     t = list(test_dict.keys())[i]
  58.  
  59.     for k in list(test_dict.keys())[i+1:]:
  60.         stat, p = wilcoxon(test_dict[t], test_dict[k])
  61.  
  62.         if p < 0.05:
  63.             print(t + "  " + k)
  64.             print('Statistics=%f, p=%f' % (stat, p))
  65.             print("")
  66.  
  67.     i += 1
  68.  
  69. """
  70. import numpy as np
  71. import matplotlib.pyplot as plt
  72.  
  73. N = 5
  74. c1_f_comfort = (0,3,3,14,14)
  75. c1_s_comfort = (8,16,6,3,1)
  76.  
  77. ind = np.arange(N)      # the x locations for the groups
  78. width = 0.35            # the width of the bars
  79.  
  80. fig, ax = plt.subplots()
  81. rects1 = ax.bar(ind, c1_f_comfort, width, color='r')
  82.  
  83. rects2 = ax.bar(ind + width, c1_s_comfort, width, color='b')
  84.  
  85. # add some text for labels, title and axes ticks
  86. ax.set_ylabel('Comfort Level')
  87. ax.set_title('Context 1 Comfort Count Comparison')
  88. ax.set_xticks(ind + width / 2)
  89. ax.set_xticklabels(('Very Un', 'Un', 'Neu', 'Com', 'Very Com'))
  90.  
  91. ax.legend((rects1[0], rects2[0]), ('Friend', 'Stranger'))
  92.  
  93.  
  94. def autolabel(rects):
  95.   # Attach a text label above each bar displaying its height
  96.   for rect in rects:
  97.       height = rect.get_height()
  98.       ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
  99.               '%d' % int(height),
  100.               ha='center', va='bottom')
  101.  
  102. autolabel(rects1)
  103. autolabel(rects2)
  104.  
  105. plt.show()
  106. """
  107.  
  108.  
  109. """
  110. # libraries
  111. import numpy as np
  112. import matplotlib.pyplot as plt
  113. from matplotlib import rc
  114. import pandas as pd
  115.  
  116. # Data
  117. r = [0]
  118.  
  119. raw_data = {'greenBars': [20], 'orangeBars': [20],'blueBars': [20], 'purpleBars' : [20], 'greyBars' : [20]}
  120.  
  121. df = pd.DataFrame(raw_data)
  122.  
  123. # From raw value to percentage
  124. totals = [i+j+k+x+y for i,j,k,x,y in zip(df['greenBars'], df['orangeBars'], df['blueBars'], df['purpleBars'], df['greyBars'])]
  125.  
  126. greenBars = [i / j * 100 for i,j in zip(df['greenBars'], totals)]
  127. orangeBars = [i / j * 100 for i,j in zip(df['orangeBars'], totals)]
  128. blueBars = [i / j * 100 for i,j in zip(df['blueBars'], totals)]
  129.  
  130. # #A569BD
  131. purpleBars = [i / j * 100 for i,j in zip(df['purpleBars'], totals)]
  132.  
  133. # #5D6D7E
  134. greyBars = [i / j * 100 for i,j in zip(df['greyBars'], totals)]
  135.  
  136. # plot
  137. barWidth = 0.5
  138. names = ('A')
  139.  
  140. # Create green Bars
  141. plt.bar(r, greenBars, color='#b5ffb9', edgecolor='white', width=barWidth, label="group A")
  142.  
  143. # Create orange Bars
  144. plt.bar(r, orangeBars, bottom=greenBars, color='#f9bc86', edgecolor='white', width=barWidth, label="group B")
  145.  
  146. # Create blue Bars
  147. plt.bar(r, blueBars, bottom=[i+j for i,j in zip(greenBars, orangeBars)], color='#a3acff', edgecolor='white', width=barWidth, label="group C")
  148.  
  149. # Create purple Bars
  150. plt.bar(r, purpleBars, bottom=[i+j+k for i,j,k in zip(blueBars, greenBars, orangeBars)], color='#a569bd', edgecolor='white', width=barWidth, label="group D")
  151.  
  152. # Create grey Bars
  153. plt.bar(r, greyBars, bottom=[i+j+k+l for i,j,k,l in zip(purpleBars, blueBars, greenBars, orangeBars)], color='#5d6d7e', edgecolor='white', width=barWidth, label="group E")
  154.  
  155. # Custom x axis
  156. plt.xticks(r, names)
  157. plt.xlabel("group")
  158.  
  159. # Show graphic
  160. plt.show()
  161. """
  162.  
  163.  
  164. import numpy as np
  165. import matplotlib.pyplot as plt
  166. # import matplotlib.axes as axes
  167.  
  168. x_labels = ['C1F', 'C1S']
  169.  
  170. ind = [0, 1]
  171.  
  172. c1_f_percentages = array_to_percentages(c1_f_comfort)
  173. c1_s_percentages = array_to_percentages(c1_s_comfort)
  174.  
  175. print(c1_f_percentages)
  176. print(c1_s_percentages)
  177.  
  178. plt.box(on=None)
  179.  
  180. plt.bar(ind[0], c1_f_percentages[4], width=0.3, label='1', color='green', bottom=c1_f_percentages[3]+c1_f_percentages[2]+c1_f_percentages[1]+c1_f_percentages[0])
  181. plt.bar(ind[0], c1_f_percentages[3], width=0.3, label='2', color='blue', bottom=c1_f_percentages[2]+c1_f_percentages[1]+c1_f_percentages[0])
  182. plt.bar(ind[0], c1_f_percentages[2], width=0.3, label='3', color='#5d6d7e', bottom=c1_f_percentages[1]+c1_f_percentages[0])
  183. plt.bar(ind[0], c1_f_percentages[1], width=0.3, label='4', color='#a569bd', bottom=c1_f_percentages[0])
  184. plt.bar(ind[0], c1_f_percentages[0], width=0.3, label='5', color='#a3acff')
  185.  
  186. plt.bar(ind[1], c1_s_percentages[4], width=0.3, label='1', color='green', bottom=c1_s_percentages[3]+c1_s_percentages[2]+c1_s_percentages[1]+c1_s_percentages[0])
  187. plt.bar(ind[1], c1_s_percentages[3], width=0.3, label='2', color='blue', bottom=c1_s_percentages[2]+c1_s_percentages[1]+c1_s_percentages[0])
  188. plt.bar(ind[1], c1_s_percentages[2], width=0.3, label='3', color='#5d6d7e', bottom=c1_s_percentages[1]+c1_s_percentages[0])
  189. plt.bar(ind[1], c1_s_percentages[1], width=0.3, label='4', color='#a569bd', bottom=c1_s_percentages[0])
  190. plt.bar(ind[1], c1_s_percentages[0], width=0.3, label='5', color='#a3acff')
  191.  
  192. plt.grid(axis='y')
  193.  
  194. ax = plt.axes()
  195.  
  196. ax.set_axisbelow(True)
  197.  
  198. plt.xticks(ind, x_labels)
  199. plt.ylabel("Y LABEL")
  200. plt.ylim=1.0
  201.  
  202. plt.tick_params(
  203.     axis='both',        # changes apply to both axes
  204.     which='both',       # both major and minor ticks are affected
  205.     bottom=False,       # ticks along the bottom edge are off
  206.     left=False,
  207.     right=False,
  208.     top=False           # ticks along the top edge are off
  209.     )
  210.  
  211.  
  212. # rotate axis labels
  213. plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
  214.  
  215. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement