Skip to content
Snippets Groups Projects
Unverified Commit c054494e authored by Shamith Achanta's avatar Shamith Achanta Committed by GitHub
Browse files

Update plotter.py

parent f8d2665c
No related branches found
No related tags found
No related merge requests found
import os
import sys
import json
from matplotlib import pyplot as my_plt
from matplotlib import patches as my_patch
......@@ -7,32 +6,32 @@ import pandas as pd
import numpy as np
class JSONPlotter():
def __init__(self, filename, rename, f):
def __init__(self, log_name, plot_name, func, x_eval=True):
try:
os.remove(rename)
os.remove(plot_name)
except OSError:
pass
self.change(filename, rename)
self.plot(rename, f)
self.change(log_name, plot_name)
self.plot(plot_name, func, x_eval)
self.lines = []
def change(self, filename, rename):
with open(filename, "r") as f:
def change(self, log_name, plot_name):
with open(log_name, "r") as f:
file_data = f.read()
with open(filename, "r") as f:
with open(log_name, "r") as f:
self.lines = f.readlines()
first_line = self.lines[0]
file_lines = [''.join([',', line.strip(), '\n']) for line in self.lines[1:]]
with open(rename, "w+") as f:
with open(plot_name, "w+") as f:
f.write('{' + '\n' + ' ' + '"logs"' + ':' + ' ' + '[' + '\n')
f.writelines(first_line)
f.writelines(file_lines)
f.write(" " + "]" + "\n" + "}")
def plot(self, rename, f):
with open(rename) as json_file:
def plot(self, plot_name, func, x_eval=True):
with open(plot_name) as json_file:
data = pd.DataFrame(json.load(json_file)['logs'])
_x = data['params'].to_list()
......@@ -42,14 +41,19 @@ class JSONPlotter():
for i in range(dim):
x_list[i].append(tuple(x_.values())[i])
x_eval = np.arange(1, len(self.lines)+1, 1)
n_eval = np.arange(1, len(self.lines)+1, 1)
y = data['target'].to_numpy()
if x_eval:
x = n_eval
else:
x = x_list[0]
my_plt.figure('FmFnBO')
my_plt.title("function = {} :: evaluations = {}".format(f, len(self.lines)))
my_plt.title("function = {} :: evaluations = {}".format(func, len(self.lines)))
blue = my_patch.Patch(color='blue', label='fmfn')
my_plt.legend(handles=[blue])
my_plt.plot(x_list[0], y, 'b')
my_plt.plot(x, y, 'b')
my_plt.show()
\ No newline at end of file
my_plt.show()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment