plot_whisker.py
This file
Path
scripts/plot_whisker.py
43 lines · 1.3 KiB · Python
Last changed by
scripts: modify shebang to use "/usr/bin/env python"muxatorbefore adoption5a80a23
History of this fileTake it
1#!/usr/bin/env python23"""This program shows `hyperfine` benchmark results as a box and whisker plot.45Quoting from the matplotlib documentation:6 The box extends from the lower to upper quartile values of the data, with7 a line at the median. The whiskers extend from the box to show the range8 of the data. Flier points are those past the end of the whiskers.9"""1011import argparse12import json13import matplotlib.pyplot as plt1415parser = argparse.ArgumentParser(description=__doc__)16parser.add_argument("file", help="JSON file with benchmark results")17parser.add_argument("--title", help="Plot Title")18parser.add_argument(19 "--labels", help="Comma-separated list of entries for the plot legend"20)21args = parser.parse_args()2223with open(args.file) as f:24 results = json.load(f)["results"]2526if args.labels:27 labels = args.labels.split(",")28else:29 labels = [b["command"] for b in results]30times = [b["times"] for b in results]3132boxplot = plt.boxplot(times, vert=True, patch_artist=True)33cmap = plt.cm.get_cmap("rainbow")34colors = [cmap(val / len(times)) for val in range(len(times))]3536for patch, color in zip(boxplot["boxes"], colors):37 patch.set_facecolor(color)3839plt.title(args.title)40plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")41plt.ylabel("Time [s]")42plt.ylim(0, None)43plt.show()