plot_whisker.py
This file
Path
scripts/plot_whisker.py
37 lines · 1.2 KiB · Python
Last changed by
Remove unnecessary importssharkdpbefore adoptionb702292
History of this fileTake it
Add a script to plot histogramssharkdpbefore adoptionef8a166
lines 1–16why, one step back1#!/usr/bin/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")Update plot_whisker.pyEugene Obrezkovbefore adoptione83e1f7
line 17why, one step back17parser.add_argument("--title", help="Plot Title")Add a script to plot histogramssharkdpbefore adoptionef8a166
lines 18–25why, one step back18args = parser.parse_args()1920with open(args.file) as f:21 results = json.load(f)["results"]2223commands = [b["command"] for b in results]24times = [b["times"] for b in results]25Update plot_whisker.pyEugene Obrezkovbefore adoptione83e1f7
lines 26–34why, one step back26boxplot = plt.boxplot(times, vert=True, patch_artist=True)27cmap = plt.cm.get_cmap("rainbow")28colors = [cmap(val / len(times)) for val in range(len(times))]2930for patch, color in zip(boxplot["boxes"], colors):31 patch.set_facecolor(color)3233plt.title(args.title)34plt.legend(handles=boxplot["boxes"], labels=commands, loc="best", fontsize="medium")Add a script to plot histogramssharkdpbefore adoptionef8a166
line 35why, one step back35plt.ylabel("Time [s]")Update plot_whisker.pyEugene Obrezkovbefore adoption9253e9f
line 36why, one step back36plt.ylim(0, None)Add a script to plot histogramssharkdpbefore adoptionef8a166
line 37why, one step back37plt.show()