''' DS2000 Spring 2020 Sample code - functions that use matplotlib to graph soccer W/L/D record ''' import matplotlib.pyplot as plt WIN = 'W' LOSS = 'L' DRAW = 'D' def graph_record(record, title): ''' Function: graph_record Parameters: record, a list of W/L/D; and title, a string to put as the title of the graph Returns: nothing ''' plot_data = [] data_point = 0 for game in record: if game == WIN: data_point += 5 elif game == LOSS: data_point -= 5 plot_data.append(data_point) plt.plot(plot_data) plt.xlabel('Game #') plt.ylabel('Win/Loss/Draw') plt.title(title) plt.show() def graph_goals(goals, record, title): ''' Function: graph_record Parameters: goals, a list of # goals scored per game; record, a list of W/L/D; and title, a string to put as the title of the graph Returns: nothing ''' list_of_days = [i for i in range(0, len(goals))] possible_goals = [i for i in range(0, max(goals) + 1)] colors = [] for outcome in record: if outcome == WIN: colors.append('purple') elif outcome == DRAW: colors.append('green') else: colors.append('orange') plt.scatter(list_of_days, goals, c = colors) plt.xlabel('Game #') plt.ylabel('Number of goals') plt.yticks(possible_goals) plt.title(title) plt.show()