Skip to content

Commit 2640fa9

Browse files
authored
Benchmark graph improvements (pytorch#329)
1 parent 76900f6 commit 2640fa9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

benchmarks/decoders/benchmark_decoders_library.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -414,28 +414,34 @@ def plot_data(df_data, plot_path):
414414
color=[colors(i) for i in range(len(group))],
415415
align="center",
416416
capsize=5,
417+
label=group["decoder"],
417418
)
418419

419420
# Set the labels
420421
ax.set_xlabel("FPS")
421-
ax.set_ylabel("Decoder")
422422

423-
# Reverse the order of the handles and labels to match the order of the bars
424-
handles = [
425-
plt.Rectangle((0, 0), 1, 1, color=colors(i)) for i in range(len(group))
426-
]
427-
ax.legend(
428-
handles[::-1],
429-
group["decoder"][::-1],
430-
title="Decoder",
431-
loc="upper right",
432-
)
423+
# No need for y-axis label past the plot on the far left
424+
if col == 0:
425+
ax.set_ylabel("Decoder")
433426

434427
# Remove any empty subplots for videos with fewer combinations
435428
for row in range(len(unique_videos)):
436429
for col in range(video_type_combinations[unique_videos[row]], max_combinations):
437430
fig.delaxes(axes[row, col])
438431

432+
# If we just call fig.legend, we'll get duplicate labels, as each label appears on
433+
# each subplot. We take advantage of dicts having unique keys to de-dupe.
434+
handles, labels = plt.gca().get_legend_handles_labels()
435+
unique_labels = dict(zip(labels, handles))
436+
437+
# Reverse the order of the handles and labels to match the order of the bars
438+
fig.legend(
439+
handles=reversed(unique_labels.values()),
440+
labels=reversed(unique_labels.keys()),
441+
frameon=True,
442+
loc="right",
443+
)
444+
439445
# Adjust layout to avoid overlap
440446
plt.tight_layout()
441447

-10.4 KB
Loading

0 commit comments

Comments
 (0)