1 |
#!/usr/bin/env python |
2 |
# -*- coding: iso-8859-15 -*- |
3 |
######################## -*- coding: utf-8 -*- |
4 |
"""Usage: plotfc.py INPUTFILE |
5 |
""" |
6 |
import matplotlib.pyplot as plt |
7 |
import numpy as np |
8 |
import sys |
9 |
from getopt import gnu_getopt as getopt |
10 |
# parse command-line arguments |
11 |
try: |
12 |
optlist,args = getopt(sys.argv[1:], ':', ['verbose']) |
13 |
print(len(args)) |
14 |
assert len(args) == 1 |
15 |
except (AssertionError): |
16 |
sys.exit(__doc__) |
17 |
|
18 |
fname=args[0] |
19 |
print("reading from "+fname) |
20 |
|
21 |
def get_output (fname, mystring): |
22 |
"""parse fname and get some numbers out""" |
23 |
iters = [] |
24 |
simuls= [] |
25 |
fc = [] |
26 |
try: |
27 |
f=open(fname) |
28 |
except: |
29 |
print(fname + " does not exist, continuing") |
30 |
else: |
31 |
for line in f: |
32 |
if mystring in line: |
33 |
ll = line.split() |
34 |
iters.append( int(ll[2].replace(',',''))) |
35 |
simuls.append(int(ll[4].replace(',',''))) |
36 |
fc.append( float(ll[6].replace('D','e').replace(',',''))) |
37 |
|
38 |
return iters, simuls, fc |
39 |
|
40 |
iters, simuls, fc = get_output(fname, "f=") |
41 |
# sort out restarts |
42 |
iters0 = np.asarray(iters) |
43 |
for k,it in enumerate(iters[0:]): |
44 |
if iters0[k]<iters0[k-1]: |
45 |
iters0[k:] = iters0[k:]+(iters0[k-1]-iters0[k]+1) |
46 |
|
47 |
fig, ax1 = plt.subplots() |
48 |
ax1.semilogy(iters0,(np.asarray(fc)-fc[-1]),'bx-') |
49 |
ax1.set_xlabel('iterations') |
50 |
ax1.set_ylabel('fc-min(fc)', color='b') |
51 |
ax1.tick_params('y', colors='b') |
52 |
ax1.grid() |
53 |
|
54 |
ax2 = ax1.twinx() |
55 |
ax2.plot(iters0,simuls, 'r.') |
56 |
ax2.set_ylabel('# simulations', color='r') |
57 |
ax2.tick_params('y', colors='r') |
58 |
|
59 |
plt.show() |