Mercurial > hg > numerics
comparison numerics/bar.py @ 115:7fac47bb648e
mysteries and more mysteries: bokeh should really be a plugin for this, not the way to do it, but we are porting so lets ignore that and boldly walk forward
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sun, 15 Mar 2015 17:03:38 -0700 |
parents | f9900883db2e |
children | fe820a3afa48 |
comparison
equal
deleted
inserted
replaced
114:8b5fba91dac5 | 115:7fac47bb648e |
---|---|
8 - http://bokeh.pydata.org/tutorial/solutions/gallery/olympics.html | 8 - http://bokeh.pydata.org/tutorial/solutions/gallery/olympics.html |
9 """ | 9 """ |
10 | 10 |
11 # imports | 11 # imports |
12 import argparse | 12 import argparse |
13 #import pandas as pd | |
14 import sys | 13 import sys |
14 from .data import transpose | |
15 from .manipulate import ManipulationParser | 15 from .manipulate import ManipulationParser |
16 #from .read import CSVParser | |
17 from bokeh.charts import Bar | 16 from bokeh.charts import Bar |
18 from bokeh.plotting import * | 17 from bokeh.plotting import * |
18 from collections import OrderedDict | |
19 | 19 |
20 __all__ = ['bar_chart', 'BarChartParser', 'main'] | 20 __all__ = ['bar_chart', 'BarChartParser', 'main'] |
21 | |
21 | 22 |
22 def bar_chart(data, output): | 23 def bar_chart(data, output): |
23 """create a bar chart""" | 24 """create a bar chart""" |
24 | 25 |
25 bar = Bar(data, tools="pan,wheel_zoom,box_zoom,reset,resize") | 26 bar = Bar(data, tools="pan,wheel_zoom,box_zoom,reset,resize") |
47 options = parser.parse_args(args) | 48 options = parser.parse_args(args) |
48 | 49 |
49 # process data | 50 # process data |
50 data = parser.typed_data() | 51 data = parser.typed_data() |
51 | 52 |
53 # ensure a mapping is given | |
54 if len(data) == 1: | |
55 data.insert(0, range(len(data[-1]))) | |
56 if len(data) != 2: | |
57 parser.error("A mapping is required") | |
58 mapping = OrderedDict(transpose(data)) | |
59 | |
52 # generate bar chart | 60 # generate bar chart |
53 bar_chart(data, options.output) | 61 bar_chart(mapping, options.output) |
54 | 62 |
55 # BBB keeping this around for reference; | 63 # BBB keeping this around for reference; |
56 # we should probably move to a better parsing system at some point | 64 # we should probably move to a better parsing system at some point |
57 # parse file | 65 # parse file |
58 # data = pd.read_csv(options.input, header=None, names=options.columns, index_col=0) | 66 # data = pd.read_csv(options.input, header=None, names=options.columns, index_col=0) |