Skip to content

Instantly share code, notes, and snippets.

@cj3kim
Created April 21, 2017 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cj3kim/3cfce8283589bd2329c276d97f968e4b to your computer and use it in GitHub Desktop.
Save cj3kim/3cfce8283589bd2329c276d97f968e4b to your computer and use it in GitHub Desktop.
import os, sys, csv
from os import listdir
from os.path import join, isdir
from operator import itemgetter
from ast import literal_eval
import re
import matplotlib.pyplot as plt
import shutil
def retrieve_var(var_name, file_path):
_file = open(file_path)
dummy_coefficients = None
while True:
string = _file.readline()
match = re.match(var_name, string)
if match:
splits = string.split(":")
coefficients = splits[1]
coefficients = coefficients.strip()
dummy_coefficients = literal_eval(coefficients)
_file.close()
break
return dummy_coefficients
start_dir = sys.argv[1]
coeffs_amount = 5
test_no = 1
xs = []
ys = []
for c in range(coeffs_amount):
#generate graph object and use it to build a graph for each coefficient
test_no = c + 1
xs.append(test_no)
#grab the cth test from each directory and it's highest fit
file_name = 'general_info.txt'
file_path = join(start_dir, '14-dimensions', 'test-{0}'.format(test_no), file_name)
best_fit = retrieve_var('best_fit', file_path)
print 'best_fit: {0}'.format(best_fit)
ys.append(best_fit)
#build a graph with the fit as the y axis and elb as the x-axis
test_no += 1
print 'ys: {0}'.format(ys)
print 'xs: {0}'.format(xs)
plt.plot(xs, ys)
png_file_name = '{0}-graph'.format(start_dir)
plt.savefig(png_file_name)
os.system("open {0}.png".format(png_file_name))
@cj3kim
Copy link
Author

cj3kim commented Apr 21, 2017

import matplotlib.pyplot as plt

test_no = 1
xs = []
ys = []

print 'ys: {0}'.format(ys)
print 'xs: {0}'.format(xs)
plt.plot(xs, ys)

png_file_name = '{0}-graph'.format(start_dir)
plt.savefig(png_file_name)

os.system("open {0}.png".format(png_file_name))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment