Project-4/python_scripts/timing.py
2023-12-05 19:22:22 +01:00

63 lines
1.5 KiB
Python

from os import makedirs
from pathlib import Path
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_theme()
params = {
"font.family": "Serif",
"font.serif": "Roman",
"text.usetex": True,
"axes.titlesize": "large",
"axes.labelsize": "large",
"xtick.labelsize": "large",
"ytick.labelsize": "large",
"legend.fontsize": "medium",
}
plt.rcParams.update(params)
def plot_timing(indir, outdir):
if not (path := Path(outdir)).exists():
makedirs(path)
files = [
"lattice_sizes.txt",
"sample_sizes.txt",
]
xlabels = ["Lattice size", "Sampling size"]
outfiles = ["lattice_size.pdf", "sample_sizes.pdf"]
for file, xlabel, outfile in zip(files, xlabels, outfiles):
figure1, ax1 = plt.subplots()
x = []
parallel = []
serial = []
with open(Path(indir, file)) as f:
lines = f.readlines()
for line in lines:
l = line.strip().split(",")
x.append(float(l[0]))
parallel.append(float(l[1]))
serial.append(float(l[2]))
ax1.plot(x, parallel, label="Parallel")
ax1.plot(x, serial, label="Serial")
ax1.set_xlabel(xlabel)
ax1.set_ylabel("time (seconds)")
ax1.legend()
figure1.savefig(Path(outdir, outfile), bbox_inches="tight")
plt.close(figure1)
if __name__ == "__main__":
plot_timing(
"data/hp/timing",
"./latex/images/timing",
)