plot_histogram.py
This file
Path
scripts/plot_histogram.py
83 lines · 2.3 KiB · Python
Last changed by
add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140
History of this fileTake it
The walk stopped after 200 commits: lines older than ec43213 point at it.
Fix clippy warningsDavid Peterbefore adoptionec43213
lines 1–8why, one step back1#!/usr/bin/env python23"""This program shows `hyperfine` benchmark results as a histogram."""45import argparse6import json7import numpy as np8import matplotlib.pyplot as pltadd: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140
line 9why, one step back9import matplotlib.font_managerFix clippy warningsDavid Peterbefore adoptionec43213
lines 10–18why, one step back1011parser = argparse.ArgumentParser(description=__doc__)12parser.add_argument("file", help="JSON file with benchmark results")13parser.add_argument("--title", help="Plot title")14parser.add_argument(15 "--labels", help="Comma-separated list of entries for the plot legend"16)17parser.add_argument("--bins", help="Number of bins (default: auto)")18parser.add_argument(add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140
lines 19–23why, one step back19 "--legend-location", help="Location of the legend on plot (default: upper center)",20 choices=["upper center", "lower center", "right", "left", "best", "upper left", "upper right", "lower left", "lower right", "center left", "center right", "center"],21 default="upper center"22 )23parser.add_argument(Fix clippy warningsDavid Peterbefore adoptionec43213
lines 24–25why, one step back24 "--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"25)Add --log-count option to plot_histogram.pyDavid Peterbefore adoption77e7b6c
line 26why, one step back26parser.add_argument("-o", "--output", help="Save image to the given filename.")Fix clippy warningsDavid Peterbefore adoptionec43213
lines 27–32why, one step back27parser.add_argument(28 "--t-min", metavar="T", help="Minimum time to be displayed (seconds)"29)30parser.add_argument(31 "--t-max", metavar="T", help="Maximum time to be displayed (seconds)"32)Add --log-count option to plot_histogram.pyDavid Peterbefore adoption77e7b6c
lines 33–37why, one step back33parser.add_argument(34 "--log-count",35 help="Use a logarithmic y-axis for the event count",36 action="store_true",37)Fix clippy warningsDavid Peterbefore adoptionec43213
lines 38–55why, one step back3839args = parser.parse_args()4041with open(args.file) as f:42 results = json.load(f)["results"]4344if args.labels:45 labels = args.labels.split(",")46else:47 labels = [b["command"] for b in results]48all_times = [b["times"] for b in results]4950t_min = float(args.t_min) if args.t_min else np.min(list(map(np.min, all_times)))51t_max = float(args.t_max) if args.t_max else np.max(list(map(np.max, all_times)))5253bins = int(args.bins) if args.bins else "auto"54histtype = args.type if args.type else "bar"55add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140
line 56why, one step back56plt.figure(figsize=(10, 5))Fix clippy warningsDavid Peterbefore adoptionec43213
line 57why, one step back57plt.hist(Add --log-count option to plot_histogram.pyDavid Peterbefore adoption77e7b6c
lines 58–62why, one step back58 all_times,59 label=labels,60 bins=bins,61 histtype=histtype,62 range=(t_min, t_max),Fix clippy warningsDavid Peterbefore adoptionec43213
line 63why, one step back63)add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140
lines 64–69why, one step back64plt.legend(65 loc=args.legend_location,66 fancybox=True,67 shadow=True,68 prop={"size": 7, "family": ["Source Code Pro", "Fira Mono", "Courier New"]}69 )Fix clippy warningsDavid Peterbefore adoptionec43213
lines 70–73why, one step back7071plt.xlabel("Time [s]")72if args.title:73 plt.title(args.title)Add --log-count option to plot_histogram.pyDavid Peterbefore adoption77e7b6c
lines 74–78why, one step back7475if args.log_count:76 plt.yscale("log")77else:78 plt.ylim(0, None)Fix clippy warningsDavid Peterbefore adoptionec43213
lines 79–80why, one step back7980if args.output:add: legend modification parameters and output DPI (#758)Spreadcatbefore adoptionef9e140
line 81why, one step back81 plt.savefig(args.output, dpi=600)Fix clippy warningsDavid Peterbefore adoptionec43213
lines 82–83why, one step back82else:83 plt.show()