Advertisement
Guest User

r/AsrielUndertale Survey

a guest
Oct 25th, 2019
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 30.74 KB | None | 0 0
  1. # yes i know my code sucks shut up
  2.  
  3. import numpy as np
  4. import pandas as pd
  5. import matplotlib.pyplot as plt
  6.  
  7. # ---------------------------------------------------------------------------------------------------------------
  8.  
  9. # Define some things I'm going to use later.
  10.  
  11. colors = ['#7f7f7f', '#315feb', '#c83940', '#a55ba8', '#07975b',
  12.           '#34a416', '#9eceb9', '#e3d8e4', '#f58fef', '#e9a958',
  13.           '#106520', '#c30041', '#d106ad', '#26facd', '#5665e6',
  14.           '#621b5c', '#a50c68', '#d2ed28', '#d7b91f']
  15.  
  16. def unpack(x):
  17.     y = []
  18.     for i in x:
  19.         if isinstance(i, list):
  20.             y.extend(i)
  21.         else:
  22.             y.append(i)
  23.     return y
  24.  
  25. # ---------------------------------------------------------------------------------------------------------------
  26.  
  27. # Load data.
  28.  
  29. df = pd.read_csv(r'C:\Users\Mathe\OneDrive\Documents\AsrielUndertale Survey.csv')
  30. df = df.drop(columns='Carimbo de data/hora')
  31.  
  32. # ---------------------------------------------------------------------------------------------------------------
  33.  
  34. # Fix some of the answers and parse results.
  35.  
  36. df['What is your sexual orientation?'].iloc[33] = 'Unsure'
  37. df['What country are you from?'].iloc[[0, 2, 3, 6, 7, 10, 13, 16, 25, 29, 32, 33, 35, 36, 38, 40, 43, 46, 47, 56, 58]] = 'USA'
  38. df['What country are you from?'].iloc[[20, 23, 30, 57, 61]] = ['Canada', 'Australia', 'UK', np.nan, 'Netherlands']
  39. df['What is your religious status?'].iloc[[10, 16, 47, 48, 59]] = ['Unsure', 'Unsure', 'Asriel', 'Asriel', 'Unsure']
  40. df['What is your favorite song from Undertale?'].iloc[3] = 'Hopes and Dreams'
  41. df['What Undertale AUs have you played/watched/read?'].iloc[[3, 5, 11, 23, 30, 53, 58]] = ['Glitchtale',
  42.                                                                                            np.nan,
  43.                                                                                            'Glitchtale;Handplates;Undertale green;Unexpected guests;Sooner or Later You\'re Gonna be Mine;A Thorn In My Side',
  44.                                                                                            'Dreemurr Reborn;Endertale;Growth Spurt',
  45.                                                                                            'Dreemurr Reborn;Over The Void;Half-Hearted Dreamers;Growth Spurt',
  46.                                                                                            'Dreemurr Reborn;Storyshift;Underfell;Growth Spurt',
  47.                                                                                            'Glitchtale;Inverted Fate;Storyshift;Swaptale;Taletwist;Underfell;Underswap;Revenge - The Unseen Ending']
  48. df['What Undertale AUs have you played/watched/read?'] = df['What Undertale AUs have you played/watched/read?'].apply(lambda x: x if x is np.nan else x.split(';'))
  49. df['What Deltarune AUs have you played/watched/read?'] = df['What Deltarune AUs have you played/watched/read?'].apply(lambda x: x.replace('Nudealrt', 'Nudealert') if x is not np.nan else np.nan) # I mistyped it lol.
  50. df['What Deltarune AUs have you played/watched/read?'].iloc[[2, 5, 11, 52, 54, 59]] = ['Nudealert/Deltarune repainted;Paper Trail',
  51.                                                                                        np.nan,
  52.                                                                                        'Paper Trail',
  53.                                                                                        'Paper Trail',
  54.                                                                                        np.nan,
  55.                                                                                        'Horrorrune;Paper Trail']
  56. df['What Deltarune AUs have you played/watched/read?'] = df['What Deltarune AUs have you played/watched/read?'].apply(lambda x: x if x is np.nan else x.split(';'))
  57. df['What other Undertale/Deltarune related subreddits do you participate in?'].iloc[[11, 23, 58]] = ['Charadefensesquad;Undertale;Asriel_Defence_Squad',
  58.                                                                                                      'AsgoreDefenseSquad;Charadefensesquad;Deltarune;fluffyboi;ralsei;RalseiWithGuns;Asriel_Defence_Squad',
  59.                                                                                                      'fluffyboi']
  60. df['What other Undertale/Deltarune related subreddits do you participate in?'] = df['What other Undertale/Deltarune related subreddits do you participate in?'].apply(lambda x: x if x is np.nan else x.split(';'))
  61. df['Which of these do you think best describe Asriel?'] = df['Which of these do you think best describe Asriel?'].apply(lambda x: x if x is np.nan else x.split(';'))
  62.  
  63. # ---------------------------------------------------------------------------------------------------------------
  64.  
  65. x = np.unique(df['What is your biological sex?'].dropna(), return_counts=True)
  66. plot = plt.pie(x[1], colors=colors[1:])
  67. total = sum(x[1])
  68. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  69. plt.legend(plot[0], legends, loc=(.9, 0))
  70. plt.title('What is your biological sex?')
  71. plt.show()
  72.  
  73. # ---------------------------------------------------------------------------------------------------------------
  74.  
  75. x = np.unique(df['What is your biological sex?'].fillna('Didn\'t answer'), return_counts=True)
  76. plot = plt.pie(x[1], colors=colors)
  77. total = sum(x[1])
  78. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  79. plt.legend(plot[0], legends, loc=(.9, 0))
  80. plt.title('What is your biological sex?\n(With empty answers)')
  81. plt.show()
  82.  
  83. # ---------------------------------------------------------------------------------------------------------------
  84.  
  85. x = np.unique(df['What gender do you identify as?'].dropna(), return_counts=True)
  86. plot = plt.pie(x[1], colors=colors[1:])
  87. total = sum(x[1])
  88. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  89. plt.legend(plot[0], legends, loc=(.9, -.1))
  90. plt.title('What gender do you identify as?')
  91. plt.show()
  92.  
  93. # ---------------------------------------------------------------------------------------------------------------
  94.  
  95. x = np.unique(df['What gender do you identify as?'].fillna('Didn\'t answer'), return_counts=True)
  96. plot = plt.pie(x[1], colors=colors)
  97. total = sum(x[1])
  98. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  99. plt.legend(plot[0], legends, loc=(.9, -.1))
  100. plt.title('What gender do you identify as?\n(With empty answers)')
  101. plt.show()
  102.  
  103. # ---------------------------------------------------------------------------------------------------------------
  104.  
  105. x = np.unique(df['What is your sexual orientation?'].dropna(), return_counts=True)
  106. plot = plt.pie(x[1], colors=colors[1:])
  107. total = sum(x[1])
  108. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  109. plt.legend(plot[0], legends, loc=(.9, -.3))
  110. plt.title('What is your sexual orientation?')
  111. plt.show()
  112.  
  113. # ---------------------------------------------------------------------------------------------------------------
  114.  
  115. x = np.unique(df['What is your sexual orientation?'].fillna('Didn\'t answer'), return_counts=True)
  116. x = [[x[0][3], *x[0][:3], *x[0][4:]], [x[1][3], *x[1][:3], *x[1][4:]]]
  117. plot = plt.pie(x[1], colors=colors)
  118. total = sum(x[1])
  119. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  120. plt.legend(plot[0], legends, loc=(.9, -.3))
  121. plt.title('What is your sexual orientation?\n(With empty answers)')
  122. plt.show()
  123.  
  124. # ---------------------------------------------------------------------------------------------------------------
  125.  
  126. x = np.unique(df['What is your age?'].dropna(), return_counts=True)
  127. plot = plt.pie(x[1], colors=colors[1:])
  128. total = sum(x[1])
  129. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  130. plt.legend(plot[0], legends, loc=(.95, .08))
  131. plt.title('What is your age?')
  132. plt.show()
  133.  
  134. # ---------------------------------------------------------------------------------------------------------------
  135.  
  136. x = np.unique(df['What is your age?'].fillna('Didn\'t answer'), return_counts=True)
  137. x = [[x[0][-1], *x[0][:-1]], [x[1][-1], *x[1][:-1]]]
  138. plot = plt.pie(x[1], colors=colors)
  139. total = sum(x[1])
  140. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  141. plt.legend(plot[0], legends, loc=(.95, .05))
  142. plt.title('What is your age?\n(With empty answers)')
  143. plt.show()
  144.  
  145. # ---------------------------------------------------------------------------------------------------------------
  146.  
  147. x = np.unique(df['What country are you from?'].dropna(), return_counts=True)
  148. plot = plt.pie(x[1], colors=colors[1:])
  149. total = sum(x[1])
  150. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  151. plt.legend(plot[0], legends, loc=(.95, -.3))
  152. plt.title('What country are you from?')
  153. plt.show()
  154.  
  155. # ---------------------------------------------------------------------------------------------------------------
  156.  
  157. x = np.unique(df['What country are you from?'].fillna('Didn\'t answer'), return_counts=True)
  158. x = [[x[0][4], *x[0][:4], *x[0][5:]], [x[1][4], *x[1][:4], *x[1][5:]]]
  159. plot = plt.pie(x[1], colors=colors)
  160. total = sum(x[1])
  161. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  162. plt.legend(plot[0], legends, loc=(.95, -.4))
  163. plt.title('What country are you from?\n(With empty answers)')
  164. plt.show()
  165.  
  166. # ---------------------------------------------------------------------------------------------------------------
  167.  
  168. x = np.unique(df['What is your religious status?'].dropna(), return_counts=True)
  169. plot = plt.pie(x[1], colors=colors[1:])
  170. total = sum(x[1])
  171. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  172. plt.legend(plot[0], legends, loc=(.95, .08))
  173. plt.title('What is your religious status?')
  174. plt.show()
  175.  
  176. # ---------------------------------------------------------------------------------------------------------------
  177.  
  178. x = np.unique(df['What is your religious status?'].fillna('Didn\'t answer'), return_counts=True)
  179. x = [[x[0][5], *x[0][:5], *x[0][6:]], [x[1][5], *x[1][:5], *x[1][6:]]]
  180. plot = plt.pie(x[1], colors=colors)
  181. total = sum(x[1])
  182. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  183. plt.legend(plot[0], legends, loc=(.95, .08))
  184. plt.title('What is your religious status?\n(With empty answers)')
  185. plt.show()
  186.  
  187. # ---------------------------------------------------------------------------------------------------------------
  188.  
  189. x = np.unique(df['Do you consider yourself an anime fan?'].dropna(), return_counts=True)
  190. plot = plt.pie(x[1], colors=colors[1:])
  191. total = sum(x[1])
  192. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  193. plt.legend(plot[0], legends, loc=(.95, .08))
  194. plt.title('Do you consider yourself an anime fan?')
  195. plt.show()
  196.  
  197. # ---------------------------------------------------------------------------------------------------------------
  198.  
  199. x = np.unique(df['Do you consider yourself an anime fan?'].fillna('Didn\'t answer'), return_counts=True)
  200. plot = plt.pie(x[1], colors=colors)
  201. total = sum(x[1])
  202. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  203. plt.legend(plot[0], legends, loc=(.95, .08))
  204. plt.title('Do you consider yourself an anime fan?\n(With empty answers)')
  205. plt.show()
  206.  
  207. # ---------------------------------------------------------------------------------------------------------------
  208.  
  209. x = np.unique(df['Do you consider yourself a furry?'].dropna(), return_counts=True)
  210. plot = plt.pie(x[1], colors=colors[1:])
  211. total = sum(x[1])
  212. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  213. plt.legend(plot[0], legends, loc=(.95, .08))
  214. plt.title('Do you consider yourself a furry?')
  215. plt.show()
  216.  
  217. # ---------------------------------------------------------------------------------------------------------------
  218.  
  219. x = np.unique(df['Do you consider yourself a furry?'].fillna('Didn\'t answer'), return_counts=True)
  220. plot = plt.pie(x[1], colors=colors)
  221. total = sum(x[1])
  222. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  223. plt.legend(plot[0], legends, loc=(.95, .08))
  224. plt.title('Do you consider yourself a furry?\n(With empty answers)')
  225. plt.show()
  226.  
  227. # ---------------------------------------------------------------------------------------------------------------
  228.  
  229. x = np.unique(df['What led you to join the subreddit?'].dropna(), return_counts=True)
  230. plot = plt.pie(x[1], colors=colors[1:])
  231. total = sum(x[1])
  232. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  233. plt.legend(plot[0], legends, loc=(.95, .08))
  234. plt.title('What led you to join the subreddit?')
  235. plt.show()
  236.  
  237. # ---------------------------------------------------------------------------------------------------------------
  238.  
  239. x = np.unique(df['What led you to join the subreddit?'].fillna('Didn\'t answer'), return_counts=True)
  240. plot = plt.pie(x[1], colors=colors)
  241. total = sum(x[1])
  242. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  243. plt.legend(plot[0], legends, loc=(.95, .08))
  244. plt.title('What led you to join the subreddt?\n(With empty answers)')
  245. plt.show()
  246.  
  247. # ---------------------------------------------------------------------------------------------------------------
  248.  
  249. fig, ax = plt.subplots(figsize=(9, 4))
  250. data = df['What was your score for Extroversion?'].dropna()
  251. ax.hist(data, 100)
  252. ax.xaxis.set_ticks(range(0, 105, 5))
  253. plt.title('What was your score for Extroversion? (50 answers)')
  254. plt.show()
  255. print('Mean: ', round(data.mean(), 1))
  256. print('Median: ', data.median())
  257.  
  258. # ---------------------------------------------------------------------------------------------------------------
  259.  
  260. fig, ax = plt.subplots(figsize=(9, 4))
  261. data = df['What was your score for Emotional Stability?'].dropna()
  262. ax.hist(data, 100)
  263. ax.xaxis.set_ticks(range(0, 105, 5))
  264. ax.yaxis.set_ticks(range(7))
  265. ax.set_ylim(0, 6.3)
  266. plt.title('What was your score for Emotional Stability? (50 answers)')
  267. plt.show()
  268. print('Mean: ', round(data.mean(), 1))
  269. print('Median: ', data.median())
  270.  
  271. # ---------------------------------------------------------------------------------------------------------------
  272.  
  273. fig, ax = plt.subplots(figsize=(9, 4))
  274. data = df['What was your score for Agreeableness?'].dropna()
  275. ax.hist(data, 100)
  276. ax.xaxis.set_ticks(range(0, 105, 5))
  277. plt.title('What was your score for Agreeableness? (48 answers)')
  278. plt.show()
  279. print('Mean: ', round(data.mean(), 1))
  280. print('Median: ', data.median())
  281.  
  282. # ---------------------------------------------------------------------------------------------------------------
  283.  
  284. fig, ax = plt.subplots(figsize=(9, 4))
  285. data = df['What was your score for Conscientiousness?'].dropna()
  286. ax.hist(data, 100)
  287. ax.xaxis.set_ticks(range(0, 105, 5))
  288. ax.yaxis.set_ticks(range(7))
  289. ax.set_ylim(0, 6.3)
  290. plt.title('What was your score for Conscientiousness? (50 answers)')
  291. plt.show()
  292. print('Mean: ', round(data.mean(), 1))
  293. print('Median: ', data.median())
  294.  
  295. # ---------------------------------------------------------------------------------------------------------------
  296.  
  297. fig, ax = plt.subplots(figsize=(9, 4))
  298. data = df['What was your score for Intellect/Imagination?'].dropna()
  299. ax.hist(data, 100)
  300. ax.xaxis.set_ticks(range(0, 105, 5))
  301. plt.title('What was your score for Intellect/Imagination? (48 answers)')
  302. plt.show()
  303. print('Mean: ', round(data.mean(), 1))
  304. print('Median: ', data.median())
  305.  
  306. # ---------------------------------------------------------------------------------------------------------------
  307.  
  308. x = np.unique(df['Have you ever played Undertale yourself?'], return_counts=True)
  309. plot = plt.pie(x[1], colors=colors[1:])
  310. total = sum(x[1])
  311. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  312. plt.legend(plot[0], legends, loc=(.9, 0))
  313. plt.title('Have you ever played Undertale yourself?')
  314. plt.show()
  315.  
  316. # ---------------------------------------------------------------------------------------------------------------
  317.  
  318. x = np.unique(df['Have you ever played Deltarune yourself?'], return_counts=True)
  319. plot = plt.pie(x[1], colors=['#a55ba8', '#315feb', '#c83940'])
  320. total = sum(x[1])
  321. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  322. plt.legend(plot[0], legends, loc=(.9, 0))
  323. plt.title('Have you ever played Deltarune yourself?')
  324. plt.show()
  325.  
  326. # ---------------------------------------------------------------------------------------------------------------
  327.  
  328. def autolabel(rects, i):
  329.     for rect in rects:
  330.         height = rect.get_height()
  331.         ax[i].annotate('{}'.format(height),
  332.                        xy=(rect.get_x() + rect.get_width() / 2, height),
  333.                        xytext=(0, 3), # 3 points vertical offset
  334.                        textcoords="offset points",
  335.                        ha='center', va='bottom')
  336.  
  337. routes = ('Pacifist', 'Neutral', 'Genocide')
  338. fig, ax = plt.subplots(1, 3, figsize=(18, 4))
  339. x = ['0', '1', '2', '3', '4', '5+']
  340.  
  341. for i in range(3):
  342.     route = routes[i]
  343.     y = (len(np.where(df['If you have played Undertale yourself, how many times have you completed each of the routes? [{}]'.format(route)].dropna() == '0')[0]),\
  344.          len(np.where(df['If you have played Undertale yourself, how many times have you completed each of the routes? [{}]'.format(route)].dropna() == '1')[0]),\
  345.          len(np.where(df['If you have played Undertale yourself, how many times have you completed each of the routes? [{}]'.format(route)].dropna() == '2')[0]),\
  346.          len(np.where(df['If you have played Undertale yourself, how many times have you completed each of the routes? [{}]'.format(route)].dropna() == '3')[0]),\
  347.          len(np.where(df['If you have played Undertale yourself, how many times have you completed each of the routes? [{}]'.format(route)].dropna() == '4')[0]),\
  348.          len(np.where(df['If you have played Undertale yourself, how many times have you completed each of the routes? [{}]'.format(route)].dropna() == '5+')[0]))
  349.    
  350.     rects = ax[i].bar(x, y, width=.6, color=colors[1:])
  351.     autolabel(rects, i)
  352.     ax[i].set_title('{} ({} answers)'.format(route, sum(y)))
  353.     ax[i].set_ylim(0, 32)
  354.  
  355. fig.suptitle('If you have played Undertale yourself, how many times have you completed each of the routes?', y=1.1)
  356. plt.show()
  357.  
  358. # ---------------------------------------------------------------------------------------------------------------
  359.  
  360. def autolabel(rects):
  361.     for rect in rects:
  362.         height = int(rect.get_height())
  363.         ax.annotate('{}'.format(height),
  364.                     xy=(rect.get_x() + rect.get_width() / 2, height),
  365.                     xytext=(0, 3), # 3 points vertical offset
  366.                     textcoords="offset points",
  367.                     ha='center', va='bottom')
  368.  
  369. fig, ax = plt.subplots(figsize=(7, 4))
  370. data = np.array(df['What would you rate Undertale on a scale from 0 - 10?'].dropna()).astype('int32')
  371. data = np.array([len(np.where(data == i)[0]) for i in range(11)])
  372. rects = ax.bar(range(11), data, width=.6)
  373. ax.set_xticks(range(11))
  374. ax.set_xlim(-.5, 10.5)
  375. ax.set_ylim(0, 33)
  376. autolabel(rects)
  377. plt.title('What would you rate Undertale on a scale from 0 - 10? (62 answers)')
  378. plt.show()
  379. print('Mean: ', round((range(11)*data).sum()/data.sum(), 1))
  380.  
  381. # ---------------------------------------------------------------------------------------------------------------
  382.  
  383. def autolabel(rects):
  384.     for rect in rects:
  385.         height = int(rect.get_height())
  386.         ax.annotate('{}'.format(height),
  387.                     xy=(rect.get_x() + rect.get_width() / 2, height),
  388.                     xytext=(0, 3), # 3 points vertical offset
  389.                     textcoords="offset points",
  390.                     ha='center', va='bottom')
  391.  
  392. fig, ax = plt.subplots(figsize=(7, 4))
  393. data = np.array(df['What would you rate Deltarune on a scale from 0 - 10?'].dropna()).astype('int32')
  394. data = np.array([len(np.where(data == i)[0]) for i in range(11)])
  395. rects = ax.bar(range(11), data, width=.6)
  396. ax.set_xticks(range(11))
  397. ax.set_xlim(-.5, 10.5)
  398. ax.set_ylim(0, 33)
  399. autolabel(rects)
  400. plt.title('What would you rate Deltarune on a scale from 0 - 10? (60 answers)')
  401. plt.show()
  402. print('Mean: ', round((range(11)*data).sum()/data.sum(), 1))
  403.  
  404. # ---------------------------------------------------------------------------------------------------------------
  405.  
  406. def autolabel(rects, i, j):
  407.     """Attach a text label above each bar in *rects*, displaying its height."""
  408.     for rect in rects:
  409.         height = rect.get_height()
  410.         ax[i,j].annotate('{}'.format(height),
  411.                     xy=(rect.get_x() + rect.get_width() / 2, height),
  412.                     xytext=(0, 3),  # 3 points vertical offset
  413.                     textcoords="offset points",
  414.                     ha='center', va='bottom')
  415.  
  416. labels = ['Hate', 'Dislike', 'Neutral', 'Like', 'Love']
  417. characters = ['Alphys', 'Asgore', 'Asriel', 'Chara', 'Flowey', 'Frisk', 'Jevil', 'King', 'Kris',
  418.               'Lancer', 'Mettaton', 'Muffet', 'Papyrus', 'Ralsei', 'Rouxls Kaard', 'Sans',
  419.               'Susie', 'Toriel', 'Undyne']
  420.  
  421. x = np.arange(5)
  422. fig, ax = plt.subplots(4, 5, figsize=(30, 20))
  423. for i in range(len(characters)):
  424.     c = characters[i]
  425.     counts = [len(np.where(df['How much do you like/dislike the following characters from the franchise? [{}]'.format(c)] == 'Hate')[0]),
  426.               len(np.where(df['How much do you like/dislike the following characters from the franchise? [{}]'.format(c)] == 'Dislike')[0]),
  427.               len(np.where(df['How much do you like/dislike the following characters from the franchise? [{}]'.format(c)] == 'Neutral')[0]),
  428.               len(np.where(df['How much do you like/dislike the following characters from the franchise? [{}]'.format(c)] == 'Like')[0]),
  429.               len(np.where(df['How much do you like/dislike the following characters from the franchise? [{}]'.format(c)] == 'Love')[0])]
  430.     rects = ax[i//5,i%5].bar(x, counts, width=.5, label=c, color=['red', 'orange', 'green', 'blue', 'purple'])
  431.     autolabel(rects, i//5, i%5)
  432.     ax[i//5,i%5].set_title(c)
  433.     ax[i//5,i%5].set_xticks(x)
  434.     ax[i//5,i%5].set_xticklabels(labels)
  435.     ax[i//5,i%5].set_ylim(0, 59)
  436.  
  437. fig.delaxes(ax[-1,-1])
  438. fig.suptitle('How much do you like/dislike the following characters from the franchise?', x=.51, y=.95, fontsize=20)
  439. plt.subplots_adjust(hspace=.5)
  440. plt.show()
  441. print('Most beloved character: Asriel')
  442. print('Most disliked character: King')
  443.  
  444. # ---------------------------------------------------------------------------------------------------------------
  445.  
  446. x = np.unique(df['And who is your favorite character overall?'], return_counts=True)
  447. plot = plt.pie(x[1], colors=colors[1:])
  448. total = sum(x[1])
  449. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  450. plt.legend(plot[0], legends, loc=(1, .13))
  451. plt.title('And who is your favorite character overall?')
  452. plt.show()
  453.  
  454. # ---------------------------------------------------------------------------------------------------------------
  455.  
  456. x = np.unique(df['What is your favorite song from Undertale?'], return_counts=True)
  457. plot = plt.pie(x[1], colors=colors[1:])
  458. total = sum(x[1])
  459. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  460. plt.legend(plot[0], legends, loc=(1, -.2))
  461. plt.title('What is your favorite song from Undertale?')
  462. plt.show()
  463.  
  464. # ---------------------------------------------------------------------------------------------------------------
  465.  
  466. x = np.unique(df['What is your favorite song from Deltarune?'].dropna(), return_counts=True)
  467. plot = plt.pie(x[1], colors=colors[1:])
  468. total = sum(x[1])
  469. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  470. plt.legend(plot[0], legends, loc=(1, -.3))
  471. plt.title('What is your favorite song from Deltarune?')
  472. plt.show()
  473.  
  474. # ---------------------------------------------------------------------------------------------------------------
  475.  
  476. x = np.unique(df['What is your favorite song from Deltarune?'].fillna('Didn\'t answer'), return_counts=True)
  477. x = [[x[0][6], *x[0][:6], *x[0][7:]], [x[1][6], *x[1][:6], *x[1][7:]]]
  478. plot = plt.pie(x[1], colors=colors)
  479. total = sum(x[1])
  480. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  481. plt.legend(plot[0], legends, loc=(1, -.4))
  482. plt.title('What is your favorite song from Deltarune?\n(With empty answers)')
  483. plt.show()
  484.  
  485. # ---------------------------------------------------------------------------------------------------------------
  486.  
  487. x = np.unique(df['Which do you think is the hardest boss fight?'].dropna(), return_counts=True)
  488. plot = plt.pie(x[1], colors=colors[1:])
  489. total = sum(x[1])
  490. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  491. plt.legend(plot[0], legends, loc=(1, -.2))
  492. plt.title('Which do you think is the hardest boss fight?')
  493. plt.show()
  494.  
  495. # ---------------------------------------------------------------------------------------------------------------
  496.  
  497. x = np.unique(df['Which do you think is the hardest boss fight?'].fillna('Didn\'t answer'), return_counts=True)
  498. x = [[x[0][1], *x[0][:1], *x[0][2:]], [x[1][1], *x[1][:1], *x[1][2:]]]
  499. plot = plt.pie(x[1], colors=colors)
  500. total = sum(x[1])
  501. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  502. plt.legend(plot[0], legends, loc=(1, -.3))
  503. plt.title('Which do you think is the hardest boss fight?\n(With empty answers)')
  504. plt.show()
  505.  
  506. # ---------------------------------------------------------------------------------------------------------------
  507.  
  508. data = unpack(df['What Undertale AUs have you played/watched/read?'].fillna('None/Didn\'t answer'))
  509. x = np.unique(data, return_counts=True)
  510. x = [[x[0][20], *x[0][:20], *x[0][21:]], [x[1][20], *x[1][:20], *x[1][21:]]]
  511. total = 63
  512. fig, ax = plt.subplots(figsize=(7, 11))
  513. ax.set_xlim(right=36)
  514. rects = ax.barh(range(len(x[0])), x[1], .6, tick_label=x[0])
  515.  
  516. for rect in rects:
  517.     width = int(rect.get_width())
  518.     xloc = 5
  519.    
  520.     yloc = rect.get_y() + rect.get_height() / 2
  521.     label = '({} | {}%)'.format(width, str(round(width/total*100, 1)))
  522.     ax.annotate(label, xy=(width, yloc), xytext=(xloc, 0),
  523.                 textcoords="offset points",
  524.                 va='center', ha='left', clip_on=True)
  525.  
  526. plt.title('What Undertale AUs have you played/watched/read?')
  527. plt.show()
  528.  
  529. # ---------------------------------------------------------------------------------------------------------------
  530.  
  531. data = unpack(df['What Deltarune AUs have you played/watched/read?'].fillna('None/Didn\'t answer'))
  532. x = np.unique(data, return_counts=True)
  533. x = [[x[0][2], *x[0][:2], *x[0][3:]], [x[1][2], *x[1][:2], *x[1][3:]]]
  534. total = 63
  535. fig, ax = plt.subplots(figsize=(7, 2))
  536. ax.set_xlim(right=60)
  537. rects = ax.barh(range(len(x[0])), x[1], .5, tick_label=x[0])
  538.  
  539. for rect in rects:
  540.     width = int(rect.get_width())
  541.     xloc = 5
  542.    
  543.     yloc = rect.get_y() + rect.get_height() / 2
  544.     label = '({} | {}%)'.format(width, str(round(width/total*100, 1)))
  545.     ax.annotate(label, xy=(width, yloc), xytext=(xloc, 0),
  546.                 textcoords="offset points",
  547.                     va='center', ha='left', clip_on=True)
  548.  
  549. plt.title('What Deltarune AUs have you played/watched/read?')
  550. plt.show()
  551.  
  552. # ---------------------------------------------------------------------------------------------------------------
  553.  
  554. data = unpack(df['What other Undertale/Deltarune related subreddits do you participate in?'].fillna('None/Didn\'t answer'))
  555. x = np.unique(data, return_counts=True)
  556. x = [[x[0][11], *x[0][:11], *x[0][12:]], [x[1][11], *x[1][:11], *x[1][12:]]]
  557. total = 63
  558. fig, ax = plt.subplots(figsize=(7, 10))
  559. ax.set_xlim(right=47)
  560. rects = ax.barh(range(len(x[0])), x[1], .6, tick_label=x[0])
  561.  
  562. for rect in rects:
  563.     width = int(rect.get_width())
  564.     xloc = 5
  565.    
  566.     yloc = rect.get_y() + rect.get_height() / 2
  567.     label = '({} | {}%)'.format(width, str(round(width/total*100, 1)))
  568.     ax.annotate(label, xy=(width, yloc), xytext=(xloc, 0),
  569.                 textcoords="offset points",
  570.                 va='center', ha='left', clip_on=True)
  571.  
  572. plt.title('What other Undertale/Deltarune related subreddits do you participate in?')
  573. plt.show()
  574.  
  575. # ---------------------------------------------------------------------------------------------------------------
  576.  
  577. x = list(np.unique(df['How much do you like Asriel?'].dropna(), return_counts=True))
  578. x[0], x[1] = [*x[0][1:4], x[0][0], *x[0][4:]], [*x[1][1:4], x[1][0], *x[1][4:]]
  579. plot = plt.pie(x[1], colors=colors[1:])
  580. total = sum(x[1])
  581. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  582. plt.legend(plot[0], legends, loc=(1, -.2))
  583. plt.title('How much do you like Asriel?')
  584. plt.show()
  585.  
  586. # ---------------------------------------------------------------------------------------------------------------
  587.  
  588. x = list(np.unique(df['How much do you like Asriel?'].fillna('Didn\'t answer'), return_counts=True))
  589. x[0], x[1] = [*x[0][1:4], x[0][0], *x[0][4:]], [*x[1][1:4], x[1][0], *x[1][4:]]
  590. x[0], x[1] = [x[0][4], *x[0][:4], *x[0][5:]], [x[1][4], *x[1][:4], *x[1][5:]]
  591. plot = plt.pie(x[1], colors=colors)
  592. total = sum(x[1])
  593. legends = [x[0][i]+' ({} | {}%)'.format(str(x[1][i]), str(round(x[1][i]/total*100, 1))) for i in range(len(x[0]))]
  594. plt.legend(plot[0], legends, loc=(1, -.2))
  595. plt.title('How much do you like Asriel?\n(With empty answers)')
  596. plt.show()
  597.  
  598. # ---------------------------------------------------------------------------------------------------------------
  599.  
  600. data = unpack(df['Which of these do you think best describe Asriel?'])
  601. x = np.unique(data, return_counts=True)
  602. x[0][0], x[0][1] = x[0][1], x[0][0]
  603. x[1][0], x[1][1] = x[1][1], x[1][0]
  604. total = 63
  605. fig, ax = plt.subplots(figsize=(7, 4))
  606. ax.set_xlim(right=55)
  607. rects = ax.barh(range(len(x[0])), x[1], .5, tick_label=x[0])
  608.  
  609. for rect in rects:
  610.     width = int(rect.get_width())
  611.     xloc = 5
  612.    
  613.     yloc = rect.get_y() + rect.get_height() / 2
  614.     label = '({} | {}%)'.format(width, str(round(width/total*100, 1)))
  615.     ax.annotate(label, xy=(width, yloc), xytext=(xloc, 0),
  616.                 textcoords="offset points",
  617.                 va='center', ha='left', clip_on=True)
  618.  
  619. plt.title('Which of these do you think best describe Asriel?')
  620. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement