Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from matplotlib import pyplot as plt
- import matplotlib.cm as cm
- import numpy as np
- import os
- from glob import glob
- import csv
- from collections import OrderedDict
- import ast
- import re
- import fnmatch
- plot_title = "Area Covered 225 Robots Finite Food"
- #list of string
- data_to_import = ['total_area_covered']
- # ->
- # 0 don't draw error bars
- # 1 draw error bars
- drawError = 1
- path = []
- eff_array = ['0','50','60','70', '80', '90', '100']
- testNumber = 'FiniteFood'
- cwd = '/Users/ammacpro1/AnacondaProjects/Trophallaxis_Model_for_journal_ALR_2500_maxfood100_islandmap/Simulation_results/' + testNumber
- ##cwd = os.getcwd()
- ##cwd = cwd + "/" + testNumber
- UTfolder_reference = 'Random_No_Trophallaxis'
- UTprefix = ['Random_Trophallaxis_Generous_eff',
- 'Random_Trophallaxis_UT70LT20average_eff',
- ]
- trophFolder = 'Bots225'
- #UTfolder = ['No_Trophallaxis','Trophallaxis_generous', 'Th50','Th70','Th90',]
- UTfolderP = []
- for p in UTprefix:
- for n in range(len(eff_array)-1):
- UTfolderP.append(p + eff_array[n+1])
- UTfolder = [UTfolder_reference]
- for pf in UTfolderP:
- UTfolder.append(pf)
- UTfolderP2 = [UTfolder_reference]
- for pf in UTprefix:
- UTfolderP2.append(pf)
- for f in UTfolder:
- path.append(cwd + '/' + f + '/' + trophFolder + '/Bot*/*Summary.csv')
- data_to_plot = {}
- def analyseFolders(folder, curr_p):
- #nitialises an empty dictionary
- data = {}
- for _data in data_to_import:
- data[_data] = []
- files = glob(folder)
- for file in files:
- with open(file, 'rt') as f:
- reader = csv.reader(f, delimiter=',')
- for row in reader:
- for key in data_to_import:
- if row[0] in [key]:
- data[key].append(row[1])
- sorted_data = dict.fromkeys(data.keys(),[])
- keys = [key for key, value in data.items()]
- #print(keys)
- print('curr_p', curr_p)
- for _data in [key for key, value in data.items()]:
- #data_to_plot[_data + "_f" + UTfolderP2[curr_pref] + "_eff" + eff_array[curr_p]] = \
- data_to_plot[_data + "_eff" + eff_array[curr_p]] = \
- [float(i) for i in data[_data]]
- keys_plot = [key for key, value in data_to_plot.items()]
- print('keys_plot', keys_plot)
- #print(data_to_plot)
- fig, ax = plt.subplots()
- colors = cm.rainbow(np.linspace(0.4, 1, len(UTfolderP2)))
- widths = np.linspace(2, 0.5, len(UTfolderP2))
- #Markers = ['+','+','o','o','o','^','o','p','s']
- #LineStyles = ['--','--','-','-','-','-.',':','--']
- Markers = ['+','+','s','o','o','s','^','^','s','s','s','o','^','o','p','s']
- LineStyles = ['-','-','--','-','-','--','-','-','--',':',':','-.','-.','-','-.',':','--']
- #def plotData(drawError):
- data_mean = []
- data_sd = []
- if curr_p == 0:
- eff_cycle = ['0']
- else:
- eff_cycle = eff_array[1:]
- for effSize in eff_cycle:
- c = colors[curr_pref]
- #w = widths[curr_b]
- w = 2
- vals = []
- sd = []
- tmpArray = data_to_plot["total_area_covered_eff" + effSize]
- if tmpArray != []:
- vals = np.mean(data_to_plot["total_area_covered_eff" + effSize])
- if (drawError):
- sd = np.std(data_to_plot["total_area_covered_eff" + effSize])
- else:
- sd = 0
- if effSize == '0':
- for i in range(len(eff_array)-1):
- data_mean.append(vals)
- data_sd.append(sd)
- else:
- data_mean.append(vals)
- data_sd.append(sd)
- eff_bins = [int(x) for x in eff_array]
- eff_bins = eff_bins[1:]
- ax.errorbar(eff_bins,
- data_mean,
- data_sd,
- #sd, fmt = 'o',
- capsize = 2,
- linestyle = LineStyles[curr_pref % len(LineStyles)],
- #linestyle = "None",
- linewidth = w,
- marker = Markers[curr_pref % len(Markers)],
- #marker='o',
- color = c,
- #label = "Number of food patches = " + str(effSize))
- label = UTfolderP2[curr_pref])
- ax.legend(frameon=False, loc="best", prop={'size': 10})
- ax.set_xlabel("Eff")
- ax.set_ylabel("Average Area Covered")
- ax.set_title(plot_title)
- #plotname = path + '/' + plot_title + "_" + _data
- #fig.savefig(plotname + '.pdf', orientation='landscape')
- #fig.savefig(plotname + '.png', orientation='landscape')
- plt.show(block=False)
- ########## main
- curr_p = 0 #curr_path = current path
- curr_pref = 0
- analyseFolders(path[curr_p], curr_p)
- curr_pref += 1
- for pp in UTprefix:
- UTfolderP = []
- for n in range(len(eff_array)-1):
- UTfolderP.append(pp + eff_array[n+1])
- path = []
- for f in UTfolderP:
- path.append(cwd + '/' + f + '/' + trophFolder + '/Bot*/*Summary.csv')
- curr_p = 1
- print('path', path)
- for p in path: #p is the full path depending on which f is currently being used, f is a part of full path
- analyseFolders(p, curr_p)
- curr_p += 1
- curr_pref += 1
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement