def plot_doze (self): """ """ done = False while not done : cmd = utils.print_second_menu() if cmd == 'pie' : #Pie chart vals = [] keys = [] for i, k in enumerate(self.doze): vals.append(len(self.doze[k])) keys.append(k) plt.figure(figsize=(6,6)) plt.pie(vals, labels=keys, autopct='%1.1f%%') plt.show() elif cmd == 'line' : vals = [] keys = [] dic = {} for k, v in self.doze.items(): dic[k] = len(v) sorted_list = sorted(dic.items(), key=operator.itemgetter(1), reverse=True) for each in sorted_list: (k, v) = each vals.append(v) keys.append(k) plt.plot(vals) plt.xticks(np.arange(len(keys)), keys) plt.show() elif cmd == 'bar' : for i, k in enumerate(self.doze): plt.bar(i, len(self.doze[k])) plt.xticks(np.arange(len(self.doze)) + 0.4, self.doze.keys()) plt.show() elif cmd == 'delay' : done = False while not done : opt = utils.print_option_menu(self.dozen_dozens) if opt == 'done' : break delay = [] v = self.doze[opt + 'x'] for ind in range(len(v) - 1): delay.append(v[ind + 1] - v[ind]) plt.plot(delay, label=opt + 'x') print (delay) plt.title('Delay') plt.xlabel('Times raffled') plt.ylabel('Delay between raffles') plt.legend() plt.show() elif cmd == 'freq' : done = False while not done : opt = utils.print_option_menu(self.done) if opt == 'done' : break delay = [] v = self.doze[opt + 'x'] for ind in range(len(v) - 1): delay.append(v[ind + 1] - v[ind]) delay.sort() plt.plot(delay, label=opt + 'x') print (delay) plt.title('Delay') plt.xlabel('Times raffled') plt.ylabel('Delay between raffles') plt.legend() plt.show() elif cmd == 'done' : done = True else : print ("I don't understand the command " + cmd)
def plot_unit (self): """ """ done = False while not done : print ('') print ('\033[92m' + "The following commands are available: " + '\033[0m') print ('') print ("pie : show the data plotted on a pie chart") print ("bar : show the data plotted on a bar chart") print ("line : show the data plotted on a line chart") print ("delay : show the delay over the raffles, plus the average delay") print ("freq : show the frequency of delays") print ("done : exit the program") print ('') cmd = raw_input('\033[92m' + 'Enter a command: ' + '\033[0m') print ('') if cmd == 'pie' : #Pie chart vals = [] keys = [] for i, k in enumerate(self.unit): vals.append(len(self.unit[k])) keys.append(k) plt.figure(figsize=(6,6)) plt.pie(vals, labels=keys, autopct='%1.1f%%') plt.show() elif cmd == 'line' : vals = [] keys = [] dic = {} for k, v in self.unit.items(): dic[k] = len(v) sorted_list = sorted(dic.items(), key=operator.itemgetter(1), reverse=True) for each in sorted_list: (k, v) = each vals.append(v) keys.append(k) plt.plot(vals) plt.xticks(np.arange(len(keys)), keys) plt.show() elif cmd == 'bar' : for i, k in enumerate(self.unit): plt.bar(i, len(self.unit[k])) plt.xticks(np.arange(len(self.unit)) + 0.4, self.unit.keys()) plt.show() elif cmd == 'delay' : done = False while not done : opt = utils.print_option_menu(9) if opt == 'done' : break delay = [] v = self.unit['x' + opt] for ind in range(len(v) - 1): delay.append(v[ind + 1] - v[ind]) plt.plot(delay, label='x' + opt) print (delay) plt.show() elif cmd == 'freq' : done = False while not done : opt = utils.print_option_menu(9) if opt == 'done' : break delay = [] v = self.unit['x' + opt] for ind in range(len(v) - 1): delay.append(v[ind + 1] - v[ind]) delay.sort() plt.plot(delay, label='x' + opt) print (delay) plt.show() elif cmd == 'done' : done = True else : print ("I don't understand the command " + cmd)