generate_graph_from_config_task.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 from argparse import ArgumentParser
4 import numpy as np
5 import matplotlib.pyplot as plt
6 from matplotlib.backends.backend_pdf import PdfPages
7 
8 
9 def plot_data(ax,
10  title,
11  ylabel,
12  data_filename=None,
13  time_list=None):
14  if data_filename is None:
15  data_filename =title+'.dat'
16  data = np.genfromtxt(args.data_dirname+'/'+data_filename,
17  dtype=np.float32, delimiter=' ', names=True)
18  t = data['time']
19  for name in data.dtype.names[1:]:
20  d = data[name]
21  ax.plot(t, d, linewidth=2, label=name)
22  ax.set_ylabel(ylabel)
23 
24  ax.set_title(title, fontsize=18)
25  ax.set_xlabel('time')
26  ax.legend(loc='upper center', bbox_to_anchor=(0.5, -0.05), ncol=4)
27  ax.set_xlim(t[0], t[-1])
28  ax.grid(True)
29 
30  if time_list is not None:
31  for t in time_list:
32  ax.axvline(x=t, linewidth=0.8, color='k', linestyle='--')
33 
34 
35 if __name__ == '__main__':
36  global args
37 
38  parser = ArgumentParser()
39 
40  parser.add_argument('--data-dirname', type=str, dest="data_dirname", required=True)
41  parser.add_argument('--output-filename', type=str, dest="output_filename", required=True)
42 
43  parser.add_argument('--kin-task-time-list', nargs="*", type=float, dest="kin_task_time_list", default=None)
44  parser.add_argument('--eom-task-time-list', nargs="*", type=float, dest="eom_task_time_list", default=None)
45  parser.add_argument('--centroid-task-time-list', nargs="*", type=float, dest="centroid_task_time_list", default=None)
46  parser.add_argument('--posture-task-time-list', nargs="*", type=float, dest="posture_task_time_list", default=None)
47 
48  args = parser.parse_args()
49 
50  fig,axes = plt.subplots(nrows=10,ncols=1,figsize=(10,100))
51 
52  plot_data(axes[0], title='theta', ylabel='joint position [rad] [m]')
53  plot_data(axes[1], title='cog', ylabel='position [m]')
54  plot_data(axes[2], title='angular_momentum', ylabel='angular momentum [kg m^2 / s]')
55  plot_data(axes[3], title='wrench', ylabel='force [N] / moment [Nm]')
56 
57  plot_data(axes[4], title="kinematics_task", ylabel='position [m] / orientation [rad]', time_list=args.kin_task_time_list)
58  plot_data(axes[5], title="translational_eom_task", ylabel='force [N]', time_list=args.eom_task_time_list)
59  plot_data(axes[6], title="rotational_eom_task", ylabel='moment [Nm]', time_list=args.eom_task_time_list)
60  plot_data(axes[7], title="cog_task", ylabel='position [m]', time_list=args.centroid_task_time_list)
61  plot_data(axes[8], title="angular_momentum_task", ylabel='angular momentum [kg m^2 / s]', time_list=args.centroid_task_time_list)
62  plot_data(axes[9], title="posture_task", ylabel='joint position [rad] [m]', time_list=args.posture_task_time_list)
63 
64  plt.tight_layout()
65  fig.show()
66 
67  pdf = PdfPages(args.output_filename)
68  pdf.savefig()
69  pdf.close()
def plot_data(ax, title, ylabel, data_filename=None, time_list=None)


eus_qp
Author(s):
autogenerated on Fri May 14 2021 02:51:43