plot_bench.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 from __future__ import print_function
3 
4 import matplotlib.pyplot as plt
5 import numpy as np
6 import csv
7 import sys
8 import os
9 from itertools import chain
10 from math import pi
11 import argparse
12 
13 parser = argparse.ArgumentParser(description="Plot benchmark result csv")
14 parser.add_argument("csv_file", help="csv file")
15 parser.add_argument("--image-suffix", default="eps", help="suffix to save image")
16 parser.add_argument("--only-save-image", action="store_true", help="die right after saving image")
17 parser.add_argument("--min", default=0, type=float, help="minimum value")
18 parser.add_argument("--max", default=0.2, type=float, help="maximum value")
19 args = parser.parse_args()
20 csv_file = args.csv_file
21 methods = ['none']
22 dx = 3
23 dy = 3
24 
25 def plot(theta, one_data, ax):
26  global im
27  xs = [data[0] for data in one_data]
28  ys = [data[1] for data in one_data]
29  zs = {}
30  for x, y, i in zip(xs, ys, range(len(xs))):
31  zs[(x, y)] = one_data[i][2]
32  xs.sort()
33  ys.sort()
34 
35  minz = args.min
36  maxz = args.max
37 
38  img = np.arange(0, len(xs) * len(ys), 1.0).reshape((len(xs), len(ys)))
39  for x, i in zip(xs, range(len(xs))):
40  for y, j in zip(ys, range(len(ys))):
41  try:
42  z = zs[(x, y)]
43  except:
44  print("Failed to find (%f, %f)" % (x, y), file=sys.stderr)
45  img[j][i] = z
46  #im = ax.pcolor(img, vmin=minz, vmax=maxz, cmap="gnuplot")
47  im = ax.imshow(img, vmin=minz, vmax=maxz, cmap="gnuplot")
48  ax.set_xticklabels(np.arange(-dx - 1, dx+1))
49  ax.set_yticklabels(np.arange(-dy - 1, dy+1))
50  ax.set_xlabel("$x$ [m]")
51  ax.set_ylabel("$y$ [m]")
52  ax.set_title('$\\theta = %.0f$ deg' % (theta / pi * 180.0))
53 
54 
55 reader = csv.reader(open(csv_file))
56 fields = reader.next()
57 
58 initialized = False
59 
60 data = {}
61 # theta -> x, y, time
62 
63 for row in reader:
64  # Initialization
65  if not initialized:
66  figure_num = int(row[fields.index("n_theta")])
67  if figure_num % 3 == 0:
68  xnum = figure_num / 3
69  else:
70  xnum = figure_num / 3 + 1
71  fig, axes = plt.subplots(xnum, 3)
72  initialized = True
73  theta_str = row[fields.index("theta")]
74  theta = float(theta_str)
75  if theta_str not in data:
76  data[theta_str] = []
77  data[theta_str].append((float(row[fields.index("x")]), float(row[fields.index("y")]), float(row[fields.index("one_time")])))
78 
79 counter = 0
80 #for theta, one_data in data.items():
81 for theta in sorted(data.keys()):
82  one_data = data[theta]
83  print("Plotting theta=", theta)
84  plot(float(theta), one_data, axes.flat[counter])
85  counter = counter + 1
86 
87 for a in axes.flat[counter:]:
88  fig.delaxes(a)
89 plt.tight_layout()
90 fig.subplots_adjust(right = 0.8)
91 cbar_ax = fig.add_axes([0.85, 0.15, 0.05, 0.7])
92 cb = fig.colorbar(im, cax=cbar_ax)
93 cb.set_label("Time [sec]")
94 plt.interactive(True)
95 plt.show()
96 # save figure
97 eps_file = os.path.basename(csv_file) + "." + args.image_suffix
98 print("Saving to %s file: " % (args.image_suffix), eps_file)
99 plt.savefig(eps_file)
100 if args.only_save_image:
101  sys.exit(0)
102 while True:
103  plt.pause(1)
plot_bench.plot
def plot(theta, one_data, ax)
Definition: plot_bench.py:25
plot_bench.float
float
Definition: plot_bench.py:17


jsk_footstep_planner
Author(s): Ryohei Ueda
autogenerated on Wed Jan 24 2024 04:05:30