Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- import glob
- import csv
- import numpy as np
- MARKERS_LIST = ['o', 'v', 'D', 's', 'd']
- COLORS_LIST = ['b', 'g', 'r', 'k', 'm']
- FILES_LIST = ['rsel.csv', 'cel-rs.csv', '2cel-rs.csv', 'cel.csv', '2cel.csv']
- HEURISTICS_LIST = ['1-Evol-RS', '1-Coev-RS', '2-Coev-RS', '1-Coev', '2-Coev']
- 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 left_plot(arr, ax1, ax2, marker, color, heuristic):
- x1, y1, x2, y2 = [], [], [], []
- xScaleFactor, yScaleFactor = 1000, 100
- for row in arr[1:]:
- x1.append(row[1] / xScaleFactor)
- y1.append((sum(row[2:]) / float(len(row[2:]))) * yScaleFactor)
- if (row[0] % 30 == 0):
- x2.append(row[1] / xScaleFactor)
- y2.append((sum(row[2:]) / float(len(row[2:]))) * yScaleFactor)
- ax1.plot(x1, y1, c=color)
- ax2.scatter(x2, y2, s=30, c=color, marker=marker, label=heuristic)
- def left_plot_info(ax1, ax2):
- ax1.set_xlabel('Rozegranych gier (x1000)')
- ax1.set_ylabel('Odsetek wygranych gier [%]')
- ax1.set_xlim([0,500000 / 1000])
- ax1.set_ylim([60, 100])
- ax1.grid()
- ax2.set_xlabel('Pokolenie')
- ax2.set_xlim([0, 500000 / 1000])
- ax2.set_ylim([60, 100])
- ax2.legend(loc=4, fontsize='medium')
- ax2.set_xticks([0,100,200,300,400,500])
- ax2.set_xticklabels(['0','40','80','120','160','200']);
- def right_plot(arr):
- y = []
- for row in arr[1:]:
- y.append(sum(row[2:]) / float(len(row[2:])) * 100)
- return y
- def right_plot_info(ax, data):
- ax.boxplot(data, notch=True, bootstrap=10000)
- ax.set_xticks([1,2,3,4,5,6])
- ax.set_xticklabels(['1-Evol-RS', '1-Coev-RS', '2-Coev-RS', '1-Coev', '2-Coev'], rotation=22, fontsize=11);
- ax.yaxis.tick_right()
- ax.grid()
- def main():
- #fig = plt.figure(figsize=(6.7, 6.7)) PROPONOWANY PRZEZ PANA ROZMIAR WYKRESU
- ax1 = plt.subplot(1, 2, 1)
- ax2 = ax1.twiny()
- ax3 = plt.subplot(1, 2, 2)
- i = 0
- data = []
- #for file_name in glob.glob('*.csv'): NIE KORZYSTAM Z glob.glob, PONIEWAŻ WCZYTUJE ON PLIKI W MNIEJ WYGODNEJ KOLEJNOŚCI, PRZEZ CO TRUDNIEJ DOBRAĆ, ŻEBY KOLORY WYKRESÓW BYŁY TAKIE JAK W TREŚCI
- for filename in FILES_LIST:
- left_plot(prepare_array(read_file(filename)), ax1, ax2, MARKERS_LIST[i], COLORS_LIST[i], HEURISTICS_LIST[i])
- i += 1
- left_plot_info(ax1, ax2)
- for filename in FILES_LIST:
- data.append(right_plot(prepare_array(read_file(filename))))
- right_plot_info(ax3, data)
- #plt.savefig('na5.pdf') ODKOMENTOWAĆ JEŻELI WYKRES MA ZOSTAĆ ZAPISANY NA DYSKU
- plt.show()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement