-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
executable file
·100 lines (82 loc) · 2.23 KB
/
plot.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
from argparse import RawTextHelpFormatter
import sys
import re
import prettyplotlib as ppl
import numpy as np
from prettyplotlib import plt
"""
sample,ng/ul,Title
value1
value2
"""
def main():
description = """Simple bar plot of table. Input is a table from a file or
standard input."""
parser = argparse.ArgumentParser(
description=description,
formatter_class=RawTextHelpFormatter
)
parser.add_argument(
'-f',
'--filename',
action='store',
metavar='table.csv',
help='''A table of the format:
x_title, y_title, Main_title
x_label1, value1
x_label2, value2''',
required=False,
dest='filename',
)
args = parser.parse_args()
if args.filename:
filename = args.filename.strip()
else:
parser.print_help()
sys.exit(1)
y = []
x = []
for line in open(filename, "r").readlines():
line = line.strip()
res = re.search("[0-9]+", line)
if not res:
line = line.split(",")
x_lab = line[0]
y_lab = line[1]
main = line[2]
else:
line = line.split(",")
if len(line) < 2:
y.append(float(line[0]))
else:
x.append(line[0])
y.append(float(line[1]))
print(line)
if len(x) < 1:
x = range(1, len(y) + 1)
plt.rc('font', **{'family': 'DejaVu Sans'})
fig, ax = plt.subplots(1, figsize=(8, 6))
width = 0.2
ind = np.arange(len(y))
xdata = ind + 0.05 + width
ax.bar(ind, y)
ax.set_xticks(ind + 0.5)
ax.set_xticklabels(x)
ax.autoscale()
ax.set_title(
main,
fontdict={'fontsize': 20},
)
plt.ylabel(y_lab, fontdict={'fontsize': 15})
plt.xlabel(x_lab, fontdict={'fontsize': 15})
plt.tick_params(axis="y", which="major", labelsize=10)
plt.tick_params(axis="x", which="major", labelsize=10)
ppl.bar(ax, np.arange(len(y)), y, grid="y")
plt.tight_layout()
print("The plot has been saved as ``out.png``")
fig.savefig("out.png")
if __name__ == "__main__":
main()