from os import makedirs from pathlib import Path import matplotlib.pyplot as plt def plot_timing(indir, outdir): if not (path := Path(outdir)).exists(): makedirs(path) files = [ "lattice_sizes.txt", "sample_sizes.txt", ] labels = [ "Lattice sizes", "Sample sizes", ] xlabels = ["Lattice size", "Sampling size"] outfiles = ["lattice_size.pdf", "sample_sizes.pdf"] for file, label, xlabel, outfile in zip(files, labels, xlabels, outfiles): figure1, ax1 = plt.subplots() x = [] t = [] with open(Path(indir, file)) as f: lines = f.readlines() for line in lines: l = line.strip().split(",") x.append(float(l[0])) t.append(float(l[1])) ax1.plot(x, t, label=label) ax1.set_xlabel(xlabel) ax1.set_ylabel("time (seconds)") figure1.legend() figure1.savefig(Path(outdir, outfile)) plt.close(figure1) if __name__ == "__main__": plot_timing( "data/hp/timing/", "./latex/images/timing", )