Skip to content

Commit e3477be

Browse files
committed
Fix color
1 parent 7a26b0c commit e3477be

5 files changed

Lines changed: 54 additions & 20 deletions

File tree

config/cmr10.ttf

0 Bytes
Binary file not shown.

ompl_benchmark_plotter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def run_benchmark_plotter(input_arguments):
2424
graph_group.add_argument('--min-time', type=float, help='Specify lower bound on time display.')
2525
graph_group.add_argument('--fontsize', type=float, help='Fontsize of title and descriptions.')
2626
graph_group.add_argument('--label-fontsize', type=float, help='Fontsize of tick labels.')
27+
graph_group.add_argument('--only-success-graph', action='store_const', const=True, help='Plot only the success graph.')
2728
graph_group.add_argument('--ignore-non-optimal-planner', action='store_const', const=True, help='Do not plot non-optimal planner.')
2829
graph_group.add_argument('--legend-separate-file', action='store_const', const=True, help='Print legend as separate file.')
2930
graph_group.add_argument('--legend-below-figure', action='store_const',
@@ -57,7 +58,6 @@ def run_benchmark_plotter(input_arguments):
5758
if args.verbose > 0:
5859
print("Create optimality graphs for {} files.".format(len(args.database_files)))
5960

60-
6161
plot_config = make_config(args)
6262
plot_graph_from_databases(args.database_files, plot_config)
6363

src/database_info.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,11 @@ def make_config(args):
401401
max_time = args.max_time if args.max_time else -1
402402
min_time = args.min_time if args.min_time else -1
403403
fontsize = args.fontsize if args.fontsize else -1
404+
only_success_graph = args.only_success_graph if args.only_success_graph else False
404405
label_fontsize = args.label_fontsize if args.label_fontsize else -1
405406
plot_config = {
406407
'show': args.show,
408+
'only_success_graph': args.only_success_graph,
407409
'output_file': args.output_file,
408410
'verbosity': args.verbose,
409411
'max_cost': max_cost,

src/database_to_graph.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,12 @@ def get_errors(point):
140140
[point["cost"][2] - point["cost"][0]]])
141141
return time_errors, cost_errors
142142

143+
def init_planner_colors(data):
144+
planner_data = data["planners"]
145+
planners = list(planner_data.keys())
146+
planners.sort()
147+
for planner in planners:
148+
color = get_diverse_color(planner)
143149

144150
def plot_success(ax, data):
145151

@@ -154,9 +160,10 @@ def plot_success(ax, data):
154160
ax.set_xlim(min_time, max_time)
155161
ax.set_ylim(0.0, 100.0)
156162

163+
init_planner_colors(data)
164+
157165
planner_data = data["planners"]
158166
for planner in planner_data:
159-
#color=get_color(data, planner)
160167
color = get_diverse_color(planner)
161168
success_over_time = planner_data[planner]["success"]
162169
ax.plot(times, success_over_time, color=color,
@@ -212,48 +219,47 @@ def json_to_graph(json_filepath, pdf_filepath, config):
212219
with open(json_filepath, 'r') as jsonfile:
213220
data = json.load(jsonfile)
214221

215-
fig, axs = plt.subplots(2, 1, sharex='col', figsize=(16,10))
216-
217-
plot_success(axs[0], data)
218-
plot_optimization(axs[1], data, config)
222+
if config["only_success_graph"]:
223+
fig, axs = plt.subplots(1, 1, figsize=(16,10))
224+
plot_success(axs, data)
225+
ax_success = axs
226+
else:
227+
fig, axs = plt.subplots(2, 1, sharex='col', figsize=(16,10))
228+
ax_success = axs[0]
229+
ax_cost = axs[1]
230+
plot_success(ax_success, data)
231+
plot_optimization(ax_cost, data, config)
219232

220233
fontsize = data["info"]["fontsize"]
221234
label_fontsize = data["info"]["label_fontsize"]
222235
experiment_name = get_experiment_label(data["info"]["experiment"])
223236

224237
if 'title_name' in config:
225-
axs[0].set_title(config['title_name'], fontsize=fontsize)
238+
ax_success.set_title(config['title_name'], fontsize=fontsize)
226239
else:
227-
axs[0].set_title(experiment_name, fontsize=fontsize)
240+
ax_success.set_title(experiment_name, fontsize=fontsize)
228241

229242
legend_title_name = 'Planner'
230243
if not config["legend_none"]:
231244
if config["legend_separate_file"]:
232245
figl, axl = plt.subplots()
233-
label_params = axs[0].get_legend_handles_labels()
246+
label_params = ax_success.get_legend_handles_labels()
234247
legend = axl.legend(*label_params, loc="center", frameon=True, ncol=4, fontsize=fontsize)
235248
for obj in legend.legendHandles:
236249
obj.set_linewidth(data["info"]["legend_linewidth"])
237250
axl.axis('off')
238251
legend_filepath = change_filename_extension(json_filepath, '_legend.pdf')
239252
figl.savefig(legend_filepath, bbox_extra_artists=(legend,), bbox_inches='tight')
240253
plt.close(figl)
241-
242-
elif config['legend_below_figure']:
243-
label_params = axs[0].get_legend_handles_labels()
244-
legend = axs[1].legend(*label_params, loc='upper center', bbox_to_anchor=(0.5, -0.3),
245-
fancybox=True, ncol=4, fontsize=fontsize)
246-
for obj in legend.legendHandles:
247-
obj.set_linewidth(data["info"]["legend_linewidth"])
248-
plt.setp(legend.get_title(),fontsize=label_fontsize)
249254
else:
250-
legend = axs[0].legend(loc='upper left', title=legend_title_name, fontsize=label_fontsize)
255+
legend = ax_success.legend(loc='upper left', title=legend_title_name, fontsize=label_fontsize)
251256
for obj in legend.legendHandles:
252257
obj.set_linewidth(data["info"]["legend_linewidth"])
253258
plt.setp(legend.get_title(),fontsize=label_fontsize)
254259

255-
axs[0].tick_params(labelsize=label_fontsize)
256-
axs[1].tick_params(labelsize=label_fontsize)
260+
ax_success.tick_params(labelsize=label_fontsize)
261+
if not config["only_success_graph"]:
262+
ax_cost.tick_params(labelsize=label_fontsize)
257263

258264
fig = plt.gcf()
259265
if config['legend_separate_file'] or config['legend_none']:
@@ -282,6 +288,8 @@ def plot_graph_from_databases(database_filepaths, config):
282288
data["info"]['fontsize'] = config['fontsize']
283289
if config['label_fontsize'] > 0:
284290
data["info"]['label_fontsize'] = config['label_fontsize']
291+
if config['verbosity'] > 0:
292+
data["info"]['verbosity'] = config['verbosity']
285293

286294
experiment_names = []
287295
experiment_times = []

tests/test_ompl_benchmark_plotter.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,30 @@ def test_get_diverse_colors():
4848
assert c2 == c5
4949
assert c2 != c4
5050

51+
def test_colors_are_consistent_for_same_planner_set():
52+
json_filepath = "tests/data/simple.json"
53+
with open(json_filepath, 'r') as jsonfile:
54+
data = json.load(jsonfile)
55+
56+
init_planner_colors(data)
57+
58+
planner_data = data["planners"]
59+
planner_names = list(planner_data.keys())
60+
61+
planner_to_color_unsorted = {}
62+
for planner in planner_names:
63+
planner_to_color_unsorted[planner] = get_diverse_color(planner)
64+
65+
planner_names.sort()
66+
67+
planner_to_color_sorted = {}
68+
for planner in planner_names:
69+
planner_to_color_sorted[planner] = get_diverse_color(planner)
70+
71+
for planner in planner_names:
72+
print(planner, planner_to_color_sorted[planner], planner_to_color_unsorted[planner])
73+
assert planner_to_color_sorted[planner] == planner_to_color_unsorted[planner]
74+
5175
def test_remove_nonoptimal_planners():
5276
database_filepath = "tests/data/example.db"
5377
connection = sqlite3.connect(database_filepath)

0 commit comments

Comments
 (0)