aboutsummaryrefslogtreecommitdiff
path: root/plot.py
diff options
context:
space:
mode:
Diffstat (limited to 'plot.py')
-rwxr-xr-xplot.py66
1 files changed, 24 insertions, 42 deletions
diff --git a/plot.py b/plot.py
index d5f6863..31262c3 100755
--- a/plot.py
+++ b/plot.py
@@ -1,62 +1,44 @@
#!/usr/bin/python3
-# generate chart.svg for data
+#
+# Generate chart from JSON using matplotlib.
+#
+# (See PiBench::Runner#save_svg in run.rb for JSON details).
+#
-import csv
+import json
import sys
import os
-import re
import numpy as np
import matplotlib.pyplot as plt
-def read_csv(path):
- with open(sys.argv[1], newline = '') as fh:
- return list(reversed(list([row for row in csv.DictReader(fh)])))
-
# check arguments
-if len(sys.argv) < 3:
- print("Usage: {} input.csv output.svg title xlimit".format(sys.argv[0]))
+if len(sys.argv) < 2:
+ print("Usage: {} json_data".format(sys.argv[0]))
exit(-1)
-# read csv
-rows = read_csv(sys.argv[1])
-
-# sort by range
-# rows.sort(key = lambda row: int(row['range']))
+# decode json data from first argument
+data = json.loads(sys.argv[1])
# plot values
plt.barh(
- np.arange(len(rows)),
- [float(row['speed']) / 1048576 for row in rows],
+ np.arange(len(data['rows'])),
+ [row[1] for row in data['rows']],
align = 'center',
alpha = 0.5,
- tick_label = ['{} ({} bytes)'.format(
- row['host'],
- row['size']
- ) for row in rows]
+ tick_label = [row[0] for row in data['rows']]
)
-# # build title
-# algo = os.path.splitext(os.path.basename(sys.argv[1]))[0]
-# title = 'OpenSSL Speed Test: {}'.format(algo)
-
-# get title and xlimit
-title = sys.argv[3]
-limit = int(sys.argv[4])
-
-# # build xlimit
-# # if re.match('^aes', algo):
-# limit = 400
-# else:
-# limit = 2000
-
-# add label and title
-plt.yticks(fontsize = 5)
-plt.xlim(0, limit)
-# plt.xscale('log')
-plt.xlabel('Speed (MB/s)')
-plt.title(title, fontsize = 9)
+# set plot parameters
+plt.yticks(fontsize = data['fontsize']['yticks'])
+plt.xlim(0, data['xlimit'])
+plt.xlabel(data['xlabel'])
+plt.title(data['title'], fontsize = data['fontsize']['title'])
plt.tight_layout()
-# save image
-plt.savefig(sys.argv[2])
+# set output size
+fig = plt.gcf()
+fig.set_size_inches(data['size'][0], data['size'][1])
+
+# save plot
+plt.savefig(data['path'], dpi = data['dpi'])