Skip to content
Myr

Add parameters to plotting scripts

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Add `imgname` parameter to be able to save a plot to a file instead of showing it. Use-case: platforms without GUI like docker containers. Add `labels` parameter to histogram plot. Use-case: replacing long commands with human friendly labels.

authored by Benjamin Rosemann · committed by David Peter · parent 1f7284d · Browse files · 3 files+23 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+23 added−5 removed

  • other:+23 added−5 removed

3 files+23 added−5 removed

modified:scripts/plot_histogram.py+13 added-3 removed
8 unmodified lines
910parser = argparse.ArgumentParser(description=__doc__)11parser.add_argument("file", help="JSON file with benchmark results")12parser.add_argument("--title", help="Plot title")13parser.add_argument(14 "--labels", help="Comma-separated list of entries for the plot legend"15)16parser.add_argument("--bins", help="Number of bins (default: auto)")17parser.add_argument(18 "--type", help="Type of histogram (*bar*, barstacked, step, stepfilled)"19)20parser.add_argument("--imgname", help="Save image to the given filename.")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:22commands = [b["command"] for b in results]29 labels = [b["command"] for b in results]30all_times = [b["times"] for b in results]3132t_min = np.min(list(map(np.min, all_times)))33t_max = np.max(list(map(np.max, all_times)))
1 unmodified line
35bins = int(args.bins) if args.bins else "auto"36histtype = args.type if args.type else "bar"3738plt.hist(32 all_times, label=commands, bins=bins, histtype=histtype, range=(t_min, t_max),39 all_times, label=labels, bins=bins, histtype=histtype, range=(t_min, t_max),40)41plt.legend(prop={"family": ["Source Code Pro", "Fira Mono", "Courier New"]})4243plt.xlabel("Time [s]")44if args.title:45 plt.title(args.title)4647if args.imgname:48 plt.savefig(args.imgname)49else:40plt.show()50 plt.show()
modified:scripts/plot_parametrized.py+5 added-1 removed
23 unmodified lines
24)25parser.add_argument(26 "--titles", help="Comma-separated list of titles for the plot legend"27)28parser.add_argument("--imgname", help="Save image to the given filename.")2930args = parser.parse_args()31if args.parameter_name is not None:32 sys.stderr.write(
67 unmodified lines
100101if args.titles:102 plt.legend(args.titles.split(","))103104if args.imgname:105 plt.savefig(args.imgname)106else:103plt.show()107 plt.show()
modified:scripts/plot_whisker.py+5 added-1 removed
16 unmodified lines
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("--imgname", help="Save image to the given filename.")22args = parser.parse_args()2324with open(args.file) as f:25 results = json.load(f)["results"]
15 unmodified lines
41 plt.title(args.title)42plt.legend(handles=boxplot["boxes"], labels=labels, loc="best", fontsize="medium")43plt.ylabel("Time [s]")44plt.ylim(0, None)45if args.imgname:46 plt.savefig(args.imgname)47else:44plt.show()48 plt.show()