aboutsummaryrefslogtreecommitdiff
path: root/plot.py
blob: dcbb71436b0390789d55a5e66f92da5c6a5e00c7 (plain)
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
#!/usr/bin/python3

#
# Generate chart from JSON using matplotlib.
#
# (See PiBench::Runner#save_svg in run.rb for JSON details).
#

import json
import sys
import os
import numpy as np
import matplotlib.pyplot as plt

# check arguments
if len(sys.argv) < 2:
  print("Usage: {} json_data".format(sys.argv[0]))
  exit(-1)

# decode json data from first argument
data = json.loads(sys.argv[1])
rows = data['rows'][::-1]

# plot values
plt.barh(
  np.arange(len(rows)),
  [row[1] for row in rows],
  align = 'center',
  alpha = 0.5,
  tick_label = [row[0] for row in rows]
)

# 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()

# 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'])