-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_line_grapher.py
executable file
·90 lines (62 loc) · 2.09 KB
/
cmd_line_grapher.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
#!/usr/bin/env python3.5
import argparse
import numpy as np
import matplotlib.pyplot as plt
from Equation import Expression
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-type', default='hist', help='graph type to use. suitable options are hist, plot and scatter '
'and box')
parser.add_argument('-x', nargs='+', type=float)
parser.add_argument('-y', nargs='+', type=float)
parser.add_argument('-x_lim', nargs='+', type=float, default=None)
parser.add_argument('-y_lim', nargs='+', type=float, default=None)
parser.add_argument('-eq', type=str)
args = vars(parser.parse_args())
if args['type'] == 'hist':
draw_hist(args)
elif args['type'] == 'scatter':
draw_scatter(args)
elif args['type'] == 'plot':
draw_plot(args)
elif args['type'] == 'box':
draw_boxplot(args)
elif args['type'] == 'eq':
draw_equation(args)
else:
print('no type given')
def draw_equation(args):
eq = Expression(args['eq'])
rng = np.arange(args['x_lim'][0], args['x_lim'][1], (args['x_lim'][1]-args['x_lim'][0])/1000.0)
plt.plot(rng, [eq(a) for a in rng])
if args['x_lim'] is not None:
plt.xlim(args['x_lim'])
if args['y_lim'] is not None:
plt.xlim(args['y_lim'])
plt.show()
def draw_boxplot(args) -> None:
plt.boxplot(args['x'])
plt.show()
def draw_scatter(args) -> None:
plt.scatter(args['x'], args['y'])
if args['x_lim'] is not None:
plt.xlim(args['x_lim'])
if args['y_lim'] is not None:
plt.xlim(args['y_lim'])
plt.show()
def draw_plot(args) -> None:
plt.scatter(args['x'], args['y'])
if args['x_lim'] is not None:
plt.xlim(args['x_lim'])
if args['y_lim'] is not None:
plt.xlim(args['y_lim'])
plt.show()
def draw_hist(args: dict) -> None:
plt.hist(args['x'])
if args['x_lim'] is not None:
plt.xlim(args['x_lim'])
if args['y_lim'] is not None:
plt.xlim(args['y_lim'])
plt.show()
if __name__ == '__main__':
main()