21 Plots data from one dimensional sweeps 23 from __future__
import division
24 from builtins
import range
25 from past.utils
import old_div
28 parser = argparse.ArgumentParser(description=
'Plot one-dimensional graphs')
31 parser.add_argument(
"-nx", help=
"normalize x-values", action=
"store_true")
32 parser.add_argument(
"-ny", help=
"normalize y-values", action=
"store_true")
33 parser.add_argument(
"--ymin", type=float, help=
"minimal y-value")
34 parser.add_argument(
"--ymax", type=float, help=
"maximal y-value")
36 "-ys", type=int, help=
"Column of std-deviation of y-values")
37 parser.add_argument(
"-x", type=int, help=
"Column of x-values", default=0)
38 parser.add_argument(
"-s", type=str, help=
"Name of the simulator", default=
"")
39 parser.add_argument(
"-o", type=str, help=
"Output filename", default=
"")
42 parser.add_argument(
"-y", type=int, required=
True, help=
"Column of y-values")
43 parser.add_argument(
"files", metavar=
"files", nargs=
'+', help=
"files to plot")
45 args = parser.parse_args()
49 import matplotlib.pyplot
as plt
50 import matplotlib.colorbar
54 from dim_labels
import *
61 def plot_measure(ax, xs, ys, ys_std, color, simulator, xlabel, ylabel,
62 ys_ref=
None, first=
True, ymin=
None, ymax=
None):
64 ax.plot(xs, ys, color=color, lw=1.0, zorder=1, label=simulator)
66 if ys_std
is not None:
67 ax.plot(xs, ys - ys_std, lw=0.5,
68 linestyle=
':', color=color, zorder=0)
69 ax.plot(xs, ys + ys_std, lw=0.5,
70 linestyle=
':', color=color, zorder=0)
74 if (ymin
is None)
and (ymax
is None):
77 ax.set_ylim(bottom=ymin)
81 ax.set_ylim(bottom=ymin, top=ymax)
85 for i
in range(0, len(data)):
86 data[i] = old_div(data[i], norm)
90 idcs = np.isfinite(data)
91 return np.max(data[np.isfinite(data)])
95 idcs = np.isfinite(data)
96 return np.min(data[np.isfinite(data)])
99 ax = fig.add_subplot(111)
101 for target_file
in args.files:
102 results = np.genfromtxt(target_file, delimiter=
',', names=
True)
103 keys = results.dtype.names
104 data = np.zeros((results.shape[0], len(keys)))
105 for i
in range(0, len(results)):
106 data[i] = np.array(list(results[i]))
108 xs = np.array(data[:, args.x])
109 ys = np.array(data[:, args.y])
112 ys_dev = np.array(data[:, args.ys])
115 xlabel = DIM_LABELS[keys[args.x]]
116 ylabel = DIM_LABELS[keys[args.y]]
122 xlabel = xlabel +
" (normalized)" 125 ylabel = ylabel +
" (normalized)" 130 simulator = target_file.split(
'_')[-1].split(
'.csv')[0].split(
'.')[-1]
134 simulator=SIMULATOR_LABELS[simulator], xlabel=xlabel,
135 ylabel=ylabel, ymin=args.ymin, ymax=args.ymax)
137 if not os.path.exists(
"images"):
139 ax.legend(loc=
'lower center', bbox_to_anchor=(0.5, 1.05),
143 if args.files[-1].split(
'/')[-2]:
144 if not os.path.exists(
"images/" + args.files[-1].split(
'/')[-2]):
145 os.mkdir(
"images/" + args.files[-1].split(
'/')[-2])
146 if args.files[-1].split(
'/')[-1].split(
'_')[1] !=
"max":
147 fig.savefig(
"images/" + args.files[-1].split(
'/')[-2] +
"/" + args.files[-1].split(
148 '/')[-1].split(
'_')[0] +
".pdf", format=
'pdf', bbox_inches=
'tight')
150 fig.savefig(
"images/" + args.files[-1].split(
'/')[-2] +
"/" + args.files[-1].split(
151 '/')[-1].split(
'_')[0] +
"_max.pdf", format=
'pdf', bbox_inches=
'tight')
153 fig.savefig(
"images/" + args.files[-1].split(
'/')[-1].split(
'_')
154 [0] +
".pdf", format=
'pdf', bbox_inches=
'tight')
156 fig.savefig(args.o, format=
'pdf', bbox_inches=
'tight')
def plot_measure(ax, xs, ys, ys_std, color, simulator, xlabel, ylabel, ys_ref=None, first=True, ymin=None, ymax=None)
def normalize(data, norm)