Skip to content
Myr

plot_whisker.py

This file

Path

scripts/plot_whisker.py

51 lines · 1.5 KiB · Python

Last changed by

Use plt.get_cmap instead of plt.colormapsNicolas van Kempenbefore adoption7684efd

History of this file

Take it

The walk stopped after 200 commits: lines older than 8741d05 point at it.

Move Exporter::unit => determine_unit_from_resultsDavid Peterbefore adoption8741d05

lines 1–36why, one step back
1#!/usr/bin/env python
23"""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)21parser.add_argument(22 "-o", "--output", help="Save image to the given filename."23)2425args = parser.parse_args()2627with open(args.file) as f:28 results = json.load(f)["results"]2930if args.labels:31 labels = args.labels.split(",")32else:33 labels = [b["command"] for b in results]34times = [b["times"] for b in results]3536boxplot = plt.boxplot(times, vert=True, patch_artist=True)

Use plt.get_cmap instead of plt.colormapsNicolas van Kempenbefore adoption7684efd

line 37why, one step back
37cmap = plt.get_cmap("rainbow")

Move Exporter::unit => determine_unit_from_resultsDavid Peterbefore adoption8741d05

lines 38–51why, one step back
38colors = [cmap(val / len(times)) for val in range(len(times))]
3940for patch, color in zip(boxplot["boxes"], colors):41 patch.set_facecolor(color)4243if args.title:44 plt.title(args.title)45plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")46plt.ylabel("Time [s]")47plt.ylim(0, None)48if args.output:49 plt.savefig(args.output)50else:51 plt.show()