import glob import numpy as np import matplotlib.pyplot as plt %matplotlib inline def analyze_stats(filename): data = np.loadtxt(fname=filename, delimiter=',') return data.mean(0), data.max(0), data.min(0) datalen = 40 filenames = glob.glob('inflammation*.csv') nofiles = len(filenames) datamin = np.empty((nofiles, datalen)) datamean = np.empty_like(datamin) datamax = np.empty_like(datamin) count = 0 for f in filenames: datamean[count], datamax[count], datamin[count] = analyze_stats(f) count += 1 for count, f in enumerate(filenames): datamean[count], datamax[count], datamin[count] = analyze_stats(f) plt.imshow(datamax) plt.xlabel('Time') plt.ylabel('Dataset') plt.title('Max Values') plt.show() plt.imshow(datamean) plt.xlabel('Time') plt.ylabel('Dataset') plt.title('Mean Values') plt.show() overallmax = datamax.max(0) plt.plot(overallmax) for count in range(nofiles): for time in range(datalen): if datamax[count,time] - overallmax[time] == -1: plt.plot(time, datamax[count, time], 's') elif datamax[count,time] < overallmax[time]: plt.plot(time, datamax[count, time], 'x') else: plt.plot(time, datamax[count, time], '.') plt.xlabel('Time') plt.ylabel('Max Value') plt.show() if (1 > 0) and (-1 > 0): print 'both parts are true' else: print 'one part is not true' if (1 < 0) or ('left' < 'right'): print 'at least one test is true' def sherlock(filenames, datalen=40): datamax = np.empty((len(filenames), datalen)) for count, f in enumerate(filenames): datamax[count] = analyze_stats(f)[1] plot_clues(datamax) def plot_clues(datamax): overallmax = datamax.max(0) plt.plot(overallmax) size = datamax.shape for count in range(size[0]): for time in range(size[1]): if datamax[count, time] - overallmax[time] == -1: plt.plot(time, datamax[count, time], 's') elif datamax[count, time] < overallmax[time]: plt.plot(time, datamax[count, time], 'x') else: plt.plot(time, datamax[count, time], '.') plt.title( "Overall Maximum and Deviations Away from It\n" "dots = same as overall mean\n" "squares = exactly 1 unit less") plt.xlabel("Time (days)") plt.ylabel("Inflammation (units)") plt.show() sherlock(glob.glob('inflammation*.csv'))