Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import glob
- import csv
- def str_to_float(string):
- try:
- string = float(string)
- except ValueError:
- pass
- return string
- def read_file(filename):
- arr = []
- with open(filename, newline='') as csvfile:
- handler = csv.reader(csvfile, delimiter=',')
- for row in handler:
- arr.append(row)
- return arr
- def prepare_array(arr):
- new_arr = []
- for row in arr:
- temp = []
- for cell in row:
- temp.append(str_to_float(cell))
- new_arr.append(temp)
- return new_arr
- def prepare_plot(arr, lb):
- x, y = [], []
- for row in arr[1:]:
- x.append(row[1])
- y.append(sum(row[2:]) / float(len(row[2:])))
- plt.plot(x, y, label=lb)
- def draw_plot():
- plt.xlabel('Rozegranych gier')
- plt.ylabel('Odsetek wygranych gier')
- plt.title('Wizualizacja na 3.0')
- plt.legend(loc=4)
- plt.xlim([0,500000])
- plt.show()
- def main():
- for file_name in glob.glob('*.csv'):
- arr = read_file(file_name)
- new_arr = prepare_array(arr)
- prepare_plot(new_arr, file_name[:-4])
- draw_plot()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement