-
Notifications
You must be signed in to change notification settings - Fork 0
/
altair
executable file
·44 lines (35 loc) · 1.01 KB
/
altair
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
#!/bin/env python
"""Plot using altair
Usage:
pip install altair docopt pandas
altair mark_line [--in | --out | --encode-x | --encode-y | --open]
Options:
-h --help Show this screen.
--version Show version.
--in=<infile> Input CSV
--out=<outfile> Input HTML
--encode-x=<x> `x` argument to altair.Chart.encode [default: index].
--encode-y=<y> `y` argument to altair.Chart.encode
--open
"""
import os
import altair as alt
import pandas as pd
from docopt import docopt
DEBUG = False
def mark_line(**kwargs):
infile, outfile, x, y, open = [
kwargs[k] for k in ["--in", "--out", "--encode-x", "--encode-y", "--open"]
]
d = pd.read_csv(infile).reset_index()
chart = alt.Chart(d).mark_line().encode(x=x, y=y)
chart.save(outfile, embed_options={"renderer": "svg"})
if open:
os.system(f"open {outfile}")
arguments = docopt(__doc__) # type: ignore
if DEBUG:
print(arguments)
elif arguments["mark_line"]:
mark_line(**arguments)
else:
print(arguments)