accelerInt  v0.1
plotter.py
Go to the documentation of this file.
1 # imports
2 import matplotlib.pyplot as plt
3 import numpy as np
4 import os
5 
6 # load log files
7 files = [os.path.join('log', file) for file in os.listdir('./log/')
8  if file.endswith('.bin')]
9 files = [file for file in files if os.path.isfile(file)]
10 
11 linestyles = ['-', '--', '-.']
12 colorwheel = ['r', 'g', 'b', 'k']
13 
14 # load data
15 for i, file in enumerate(files):
16  arr = np.fromfile(file)
17  # reshape to a 2001 x 3 matrix (time, y1, y2)
18  arr = np.reshape(arr, (2001, 3))
19 
20  # get the solver name
21  label = file.split('-')[0]
22  label = label[label.index('/') + 1:]
23  label += '-GPU' if 'gpu' in file else ''
24 
25  # plot y1
26  plt.plot(arr[:, 0][::10], arr[:, 1][::10],
27  linestyle=linestyles[i % len(linestyles)],
28  label=label, color=colorwheel[i % len(colorwheel)])
29 
30 # make legend
31 plt.legend(loc=0)
32 
33 # title and labels
34 plt.title('van der Pol equation')
35 plt.xlabel('Time(s)')
36 plt.ylabel('$y_1$')
37 
38 # and save fig
39 plt.savefig('van_der_pol.png', dpi=300, size=(5, 3))