forked from glamp/bashplotlib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscatter.py
More file actions
53 lines (47 loc) · 2.11 KB
/
scatter.py
File metadata and controls
53 lines (47 loc) · 2.11 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""scatter
Usage:
scatter ((FILE | -f FILENAME) | (-X XDATA -y YDATA)) [-t TITLE -s SIZE -p MARKERSHAPE -c COLOUR] [-h -H]
Arguments:
FILE Csv with 2 columns for x and y [default: ]
-f --file FILENAME Same as FILE but shorter and less explicit [default: ]
-X --xs-file XDATA Text file with 1 column for the X values [default: ]
-y --ys-file YDATA Text file with 1 column for the y values [default: ]
-t --title TITLE Title for the chart [default: ]
-s --size SIZE Height of the histogram in lines [default: 20.0]
-p --pch MARKERSHAPE Shape of each bar [default: x]
-c --colour COLOUR Colour of the plot (Pink, blue, green, red, white, aqua, grey, yellow) [default: white]
-H --skip-header Skip the first row in FILENAME, XDATA, and YDATA [default: False]
Options:
-h --help Show this screen
Examples:
$ scatter2 -X data/exp.txt -y data/exp.txt
"""
from docopt import docopt
from bashplotlib.cli.helpers import read_stdin_or_timeout
def parse_args():
"""takes __doc__ for given cmd. Returns parsed args using docopt.
"""
args = docopt(__doc__)
for k, v in args.iteritems():
if v == 'None':
args[k] = None
if args['--file'] is None and (args['--xs-file'] is None or args['--ys-file'] is None):
print __doc__
sys.exit(1)
if args['FILE'] is not None or args['--file'] is not None:
if args['FILE'] and args['FILE'] != args['--file']:
args['--file'] = args['FILE']
if args['--file'] == 'stdin':
args['--file'] = read_stdin_or_timeout()
plot_params = {
'filename': args['--file'],
'xs': args['--xs-file'],
'ys': args['--ys-file'],
'size': float(args['--size']),
'pch': args['--pch'],
'colour': args['--colour'],
'title': args['--title'],
}
return {k: v for k,v in plot_params.items() if v is not None and v != ""}