Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- from scipy.stats import wilcoxon
- def array_to_percentages(l):
- l_sum = 0
- for i in l:
- l_sum += i
- 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)
- c1_f_comfort = [0,3,3,14,14]
- c1_s_comfort = [8,16,6,3,1]
- c2_f_comfort = [2,4,3,16,9]
- c2_s_comfort = [18,8,2,4,2]
- c3_f_comfort = [0,2,5,15,12]
- c3_s_comfort = [12,11,7,3,1]
- c4_f_comfort = [0,4,5,14,11]
- c4_s_comfort = [16,7,6,2,3]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- test_dict = {}
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- 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]
- count_dict = {}
- count_dict["c1_friend"] = [0,3,3,14,14]
- count_dict["c1_stranger"] = [8,16,6,3,1]
- count_dict["c2_friend"] = [2,4,3,16,9]
- count_dict["c2_stranger"] = [18,8,2,4,2]
- count_dict["c3_friend"] = [0,2,5,15,12]
- count_dict["c3_stranger"] = [12,11,7,3,1]
- count_dict["c4_friend"] = [0,4,5,14,11]
- count_dict["c4_stranger"] = [16,7,6,2,3]
- key_len = len( list(test_dict.keys()) )
- # String slice to get the desired results
- # Compare the samples
- i = 0
- while i < key_len:
- t = list(test_dict.keys())[i]
- for k in list(test_dict.keys())[i+1:]:
- stat, p = wilcoxon(test_dict[t], test_dict[k])
- if p < 0.05:
- print(t + " " + k)
- print('Statistics=%f, p=%f' % (stat, p))
- print("")
- i += 1
- """
- import numpy as np
- import matplotlib.pyplot as plt
- N = 5
- c1_f_comfort = (0,3,3,14,14)
- c1_s_comfort = (8,16,6,3,1)
- ind = np.arange(N) # the x locations for the groups
- width = 0.35 # the width of the bars
- fig, ax = plt.subplots()
- rects1 = ax.bar(ind, c1_f_comfort, width, color='r')
- rects2 = ax.bar(ind + width, c1_s_comfort, width, color='b')
- # add some text for labels, title and axes ticks
- ax.set_ylabel('Comfort Level')
- ax.set_title('Context 1 Comfort Count Comparison')
- ax.set_xticks(ind + width / 2)
- ax.set_xticklabels(('Very Un', 'Un', 'Neu', 'Com', 'Very Com'))
- ax.legend((rects1[0], rects2[0]), ('Friend', 'Stranger'))
- def autolabel(rects):
- # Attach a text label above each bar displaying its height
- for rect in rects:
- height = rect.get_height()
- ax.text(rect.get_x() + rect.get_width()/2., 1.05*height,
- '%d' % int(height),
- ha='center', va='bottom')
- autolabel(rects1)
- autolabel(rects2)
- plt.show()
- """
- """
- # libraries
- import numpy as np
- import matplotlib.pyplot as plt
- from matplotlib import rc
- import pandas as pd
- # Data
- r = [0]
- raw_data = {'greenBars': [20], 'orangeBars': [20],'blueBars': [20], 'purpleBars' : [20], 'greyBars' : [20]}
- df = pd.DataFrame(raw_data)
- # From raw value to percentage
- totals = [i+j+k+x+y for i,j,k,x,y in zip(df['greenBars'], df['orangeBars'], df['blueBars'], df['purpleBars'], df['greyBars'])]
- greenBars = [i / j * 100 for i,j in zip(df['greenBars'], totals)]
- orangeBars = [i / j * 100 for i,j in zip(df['orangeBars'], totals)]
- blueBars = [i / j * 100 for i,j in zip(df['blueBars'], totals)]
- # #A569BD
- purpleBars = [i / j * 100 for i,j in zip(df['purpleBars'], totals)]
- # #5D6D7E
- greyBars = [i / j * 100 for i,j in zip(df['greyBars'], totals)]
- # plot
- barWidth = 0.5
- names = ('A')
- # Create green Bars
- plt.bar(r, greenBars, color='#b5ffb9', edgecolor='white', width=barWidth, label="group A")
- # Create orange Bars
- plt.bar(r, orangeBars, bottom=greenBars, color='#f9bc86', edgecolor='white', width=barWidth, label="group B")
- # Create blue Bars
- plt.bar(r, blueBars, bottom=[i+j for i,j in zip(greenBars, orangeBars)], color='#a3acff', edgecolor='white', width=barWidth, label="group C")
- # Create purple Bars
- 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")
- # Create grey Bars
- 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")
- # Custom x axis
- plt.xticks(r, names)
- plt.xlabel("group")
- # Show graphic
- plt.show()
- """
- import numpy as np
- import matplotlib.pyplot as plt
- # import matplotlib.axes as axes
- x_labels = ['C1F', 'C1S']
- ind = [0, 1]
- c1_f_percentages = array_to_percentages(c1_f_comfort)
- c1_s_percentages = array_to_percentages(c1_s_comfort)
- print(c1_f_percentages)
- print(c1_s_percentages)
- plt.box(on=None)
- 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])
- 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])
- plt.bar(ind[0], c1_f_percentages[2], width=0.3, label='3', color='#5d6d7e', bottom=c1_f_percentages[1]+c1_f_percentages[0])
- plt.bar(ind[0], c1_f_percentages[1], width=0.3, label='4', color='#a569bd', bottom=c1_f_percentages[0])
- plt.bar(ind[0], c1_f_percentages[0], width=0.3, label='5', color='#a3acff')
- 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])
- 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])
- plt.bar(ind[1], c1_s_percentages[2], width=0.3, label='3', color='#5d6d7e', bottom=c1_s_percentages[1]+c1_s_percentages[0])
- plt.bar(ind[1], c1_s_percentages[1], width=0.3, label='4', color='#a569bd', bottom=c1_s_percentages[0])
- plt.bar(ind[1], c1_s_percentages[0], width=0.3, label='5', color='#a3acff')
- plt.grid(axis='y')
- ax = plt.axes()
- ax.set_axisbelow(True)
- plt.xticks(ind, x_labels)
- plt.ylabel("Y LABEL")
- plt.ylim=1.0
- plt.tick_params(
- axis='both', # changes apply to both axes
- which='both', # both major and minor ticks are affected
- bottom=False, # ticks along the bottom edge are off
- left=False,
- right=False,
- top=False # ticks along the top edge are off
- )
- # rotate axis labels
- plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement