forked from navjotk/error_propagation
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_gradient_error.py
More file actions
46 lines (36 loc) · 1.28 KB
/
plot_gradient_error.py
File metadata and controls
46 lines (36 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from argparse import ArgumentParser
import matplotlib
matplotlib.use('Agg')
import tikzplotlib
import matplotlib.pyplot as plt # noqa
from util import read_csv # noqa
description = ("Plot the gradient errors")
parser = ArgumentParser(description=description)
parser.add_argument("--filename", type=str, required=True)
parser.add_argument("--replacex", type=str, default=None)
parser.add_argument("--nolog", default=False, action="store_true")
args = parser.parse_args()
filename = args.filename
results = read_csv(filename)
basename = filename.split(".")[0]
xvar = 'ncp'
yvars = ['L0', 'L1', 'L2', 'Linf', 'angle', 'psnr']
replacex = args.replacex
if replacex is not None:
replacex_filename, replacex_field = replacex.split(":")
replacex_results = read_csv(replacex_filename)
x_to_plot = [replacex_results[replacex_field][replacex_results[xvar].index(x)] for x in results[xvar]] # noqa
xvar = replacex_field
else:
x_to_plot = results[xvar]
print(x_to_plot)
for yvar in yvars:
if not args.nolog:
plt.xscale('log')
plt.yscale('log')
plt.plot(x_to_plot, results[yvar])
plt.xlabel(xvar)
plt.ylabel(yvar)
plt.savefig("%s_%s_%s.pdf" % (basename, yvar, xvar), bbox_inches='tight')
tikzplotlib.save("%s_%s_%s.tex" % (basename, yvar, xvar))
plt.clf()