-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathplot.py
More file actions
76 lines (61 loc) · 2.22 KB
/
plot.py
File metadata and controls
76 lines (61 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
# Copyright (c) 2020-2021 Morwenn
# SPDX-License-Identifier: MIT
import argparse
import pathlib
import sys
import numpy
from matplotlib import pyplot
def main():
parser = argparse.ArgumentParser(description="Plot the results of the errorbar-plot benchmark.")
parser.add_argument('root', help="directory with the result files to plot")
parser.add_argument('--alternative-palette',
dest='use_alt_palette',
action='store_true',
help="Use another color palette")
args = parser.parse_args()
root = pathlib.Path(args.root)
result_files = sorted(root.glob('*.csv'))
if len(result_files) == 0:
print(f"There are no files to plot in {root}")
sys.exit(1)
# Choose the colour palette and markers to use
if args.use_alt_palette:
# That one has the advantage of being infinite
palette = pyplot.cm.rainbow(numpy.linspace(0, 1, len(result_files)))
else:
# Colorblind-friendly palette (https://gist.github.com/thriveth/8560036)
palette = ['#377eb8', '#ff7f00', '#4daf4a',
'#f781bf', '#a65628', '#984ea3',
'#999999', '#e41a1c', '#dede00']
colors = iter(palette)
markers = iter(['o', '^', 's', 'p', 'v', '*', 'H', 'X', 'd', 'P', '+'])
ax = pyplot.gca()
for result_file in result_files:
with result_file.open() as fd:
# Read the first line
algo_name = fd.readline().strip()
# Read the rest of the file
data = numpy.genfromtxt(fd, delimiter=',').transpose()
pow_of_2, size, avg, stddev = data
# Add result to graph
ax.errorbar(
size,
avg / 1000.0,
yerr=stddev / 1000.0,
label=algo_name,
color=next(colors),
marker=next(markers)
)
ax.grid(True)
ax.set_xlabel('Size')
ax.set_ylabel('Time [s] (lower is better)')
ax.set_xscale('log', base=2)
ax.set_yscale('log')
pyplot.title("Sorting std::vector<int>")
pyplot.legend(loc='best')
figure = pyplot.gcf()
figure.set_size_inches(10, 6)
pyplot.show()
if __name__ == '__main__':
main()