Skip to content

Commit ebc44f2

Browse files
committed
Minor
1 parent 2d11925 commit ebc44f2

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

ompl_benchmark_plotter.py

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22
import argparse
33
import os
4+
import re
45
from src.database_to_graph import *
56

67
############################################################
@@ -29,19 +30,38 @@ def run_benchmark_plotter(input_arguments):
2930
graph_group.add_argument('--ignore-non-optimal-planner', action='store_const', const=True, help='Do not plot non-optimal planner.')
3031
graph_group.add_argument('--ignore-planner', action='store', type=str, nargs='+', help='Exclude planners from graph (accepts multiple planner names)')
3132
graph_group.add_argument('--legend-separate-file', action='store_const', const=True, help='Print legend as separate file.')
32-
graph_group.add_argument('--legend-below-figure', action='store_const',
33-
const=True, help='Print legend below graph.')
34-
graph_group.add_argument('--legend-none', action='store_const',
35-
const=True, help='Do not print legend.')
36-
graph_group.add_argument('--remove-ylabel', action='store_const',
37-
const=True, help='Do not print label on y-axis.')
33+
graph_group.add_argument('--legend-below-figure', action='store_const', const=True, help='Print legend below graph.')
34+
graph_group.add_argument('--legend-none', action='store_const', const=True, help='Do not print legend.')
35+
graph_group.add_argument('--remove-ylabel', action='store_const', const=True, help='Do not print label on y-axis.')
3836
graph_group.add_argument('--title-name', action='store', type=str, help='Set title name.')
3937
graph_group.add_argument('--no-title', action='store_const', const=True, help='Do not set a title for this graph')
38+
graph_group.add_argument('--planner-color', type=str, action='append', help='Specify custom colors for planners as PlannerName=(R,G,B,A), e.g., --planner-color Planner1=(0.7,0.1,0.7,1.0)')
4039

4140
args = parser.parse_args(input_arguments)
4241
if args.quiet:
4342
args.verbose = 0
4443

44+
############################################################
45+
## Parse custom planner colors
46+
############################################################
47+
planner_colors = {}
48+
if args.planner_color:
49+
for color_spec in args.planner_color:
50+
match = re.match(r'(\w+)=\((\d*\.?\d+),(\d*\.?\d+),(\d*\.?\d+),(\d*\.?\d+)\)', color_spec)
51+
if match:
52+
planner_name = match.group(1)
53+
rgba = tuple(float(match.group(i)) for i in range(2, 6))
54+
if all(0 <= v <= 1 for v in rgba):
55+
planner_colors[planner_name] = rgba
56+
else:
57+
if args.verbose > 0:
58+
print(f"Error: RGBA values for {planner_name} must be between 0 and 1.")
59+
return 1
60+
else:
61+
if args.verbose > 0:
62+
print(f"Error: Invalid color format for {color_spec}. Expected PlannerName=(R,G,B,A).")
63+
return 1
64+
4565
############################################################
4666
## Sanity checks
4767
############################################################
@@ -64,9 +84,11 @@ def run_benchmark_plotter(input_arguments):
6484
print("Create optimality graphs for {} files.".format(len(args.database_files)))
6585

6686
plot_config = make_config(args)
87+
plot_config["planner_colors"] = planner_colors
6788
plot_graph_from_databases(args.database_files, plot_config)
6889

6990
return 0
7091

7192
if __name__ == '__main__':
93+
import sys
7294
sys.exit(run_benchmark_plotter(sys.argv[1:]))

src/database_to_graph.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,16 @@ def init_planner_colors(data):
149149
planner_data = data["planners"]
150150
planners = list(planner_data.keys())
151151
planners.sort()
152+
152153
for planner in planners:
153154
color = get_diverse_color(planner)
155+
print(planner,":",color)
156+
157+
if data["info"]["planner_colors"]:
158+
planner_colors = data["info"]["planner_colors"]
159+
for pcolor in planner_colors:
160+
global_color_map[pcolor] = rgba_to_hex(planner_colors[pcolor])
161+
print(pcolor,":",global_color_map[pcolor])
154162

155163
def plot_success(ax, data):
156164

@@ -307,6 +315,10 @@ def plot_graph_from_databases(database_filepaths, config):
307315
data["info"]["remove_ylabel"] = True
308316
else:
309317
data["info"]["remove_ylabel"] = False
318+
if config['planner_colors']:
319+
data["info"]['planner_colors'] = config['planner_colors']
320+
else:
321+
data["info"]['planner_colors'] = {}
310322

311323
experiment_names = []
312324
experiment_times = []

src/get_diverse_color.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,7 @@ def get_diverse_color(planner_name):
3131
hex_color = next(color_cycler)
3232
global_color_map[planner_name] = hex_color
3333
return hex_color
34+
35+
def rgba_to_hex(rgba):
36+
r, g, b, _ = [int(x * 255) for x in rgba]
37+
return f"#{r:02x}{g:02x}{b:02x}"

0 commit comments

Comments
 (0)