plot_city10000.py
Go to the documentation of this file.
1 """
2 GTSAM Copyright 2010-2019, Georgia Tech Research Corporation,
3 Atlanta, Georgia 30332-0415
4 All Rights Reserved
5 
6 See LICENSE for the license information
7 
8 Script to plot City10000 results.
9 Can be used to plot results from both C++ and python scripts.
10 
11 Usage:
12 ```
13 python plot_city10000.py ../../../examples/Data/ISAM2_GT_city10000.txt \
14  --estimates ../../../build/examples/ISAM2_city10000.txt \
15  ../../../build/examples/Hybrid_City10000.txt
16 ```
17 
18 NOTE: We can pass in as many estimates as we need,
19 though we also need to pass in the same number of --colors and --labels.
20 
21 You can generate estimates by running
22 - `make ISAM2_City10000.run` for the ISAM2 version
23 - `make Hybrid_City10000.run` for the Hybrid Smoother version
24 
25 Author: Varun Agrawal
26 """
27 
28 import argparse
29 
30 import numpy as np
31 from matplotlib import pyplot as plt
32 
33 
34 def parse_args():
35  """Parse command line arguments"""
36  parser = argparse.ArgumentParser()
37  parser.add_argument("ground_truth", help="The ground truth data file.")
38  parser.add_argument(
39  "--estimates",
40  nargs='+',
41  help="File(s) with estimates (as .txt), can be more than one.")
42  parser.add_argument("--labels",
43  nargs='+',
44  help="Label to apply to the estimate graph.",
45  default=("ISAM2", "Hybrid Factor Graphs"))
46  parser.add_argument(
47  "--colors",
48  nargs='+',
49  help="The color to apply to each of the estimate graphs.",
50  default=((0.9, 0.1, 0.1, 0.4), (0.1, 0.1, 0.9, 0.4)))
51  return parser.parse_args()
52 
53 
55  estimates,
56  fignum: int,
57  estimate_color=(0.1, 0.1, 0.9, 0.4),
58  estimate_label="Hybrid Factor Graphs"):
59  """Plot the City10000 estimates against the ground truth.
60 
61  Args:
62  gt (np.ndarray): The ground truth trajectory as xy values.
63  estimates (np.ndarray): The estimates trajectory as xy values.
64  fignum (int): The figure number for multiple plots.
65  estimate_color (tuple, optional): The color to use for the graph of estimates.
66  Defaults to (0.1, 0.1, 0.9, 0.4).
67  estimate_label (str, optional): Label for the estimates, used in the legend.
68  Defaults to "Hybrid Factor Graphs".
69  """
70  fig = plt.figure(fignum)
71  ax = fig.gca()
72  ax.axis('equal')
73  ax.axis((-65.0, 65.0, -75.0, 60.0))
74  ax.plot(gt[:, 0],
75  gt[:, 1],
76  '--',
77  linewidth=1,
78  color=(0.1, 0.7, 0.1, 0.5),
79  label="Ground Truth")
80  ax.plot(estimates[:, 0],
81  estimates[:, 1],
82  '-',
83  linewidth=1,
84  color=estimate_color,
85  label=estimate_label)
86  ax.legend()
87 
88 
89 def main():
90  """Main runner"""
91  args = parse_args()
92  gt = np.loadtxt(args.ground_truth, delimiter=" ")
93 
94  for i in range(len(args.estimates)):
95  h_poses = np.loadtxt(args.estimates[i], delimiter=" ")
96  # Limit ground truth to the number of estimates so the plot looks cleaner
97  plot_estimates(gt[:h_poses.shape[0]],
98  h_poses,
99  i + 1,
100  estimate_color=args.colors[i],
101  estimate_label=args.labels[i])
102 
103  plt.show()
104 
105 
106 if __name__ == "__main__":
107  main()
gtsam.examples.plot_city10000.plot_estimates
def plot_estimates(gt, estimates, int fignum, estimate_color=(0.1, 0.1, 0.9, 0.4), estimate_label="Hybrid Factor Graphs")
Definition: plot_city10000.py:54
gtsam.examples.plot_city10000.main
def main()
Definition: plot_city10000.py:89
gtsam::range
Double_ range(const Point2_ &p, const Point2_ &q)
Definition: slam/expressions.h:30
gtsam.examples.plot_city10000.parse_args
def parse_args()
Definition: plot_city10000.py:34
len
size_t len(handle h)
Get the length of a Python object.
Definition: pytypes.h:2448


gtsam
Author(s):
autogenerated on Wed Mar 19 2025 03:02:55