# HG changeset patch # User Jeff Hammel # Date 1426433322 25200 # Node ID 067aa27050a3c0d26a1c67b4e0ecafbdc1296502 # Parent 1b0854ee78e0bb52c8038e6c3b123f2c661c8d1e limping along towards bar charts diff -r 1b0854ee78e0 -r 067aa27050a3 numerics/bar.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/numerics/bar.py Sun Mar 15 08:28:42 2015 -0700 @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +""" +bar charts using bokeh + +See: +- http://bokeh.pydata.org/tutorial/solutions/gallery/olympics.html +""" + +# imports +import argparse +import csv +import os +import pandas as pd +import subprocess +import sys +from bokeh.charts import Bar +from bokeh.plotting import * +from collections import OrderedDict + +__all__ = ['bar_chart', 'main'] + +def bar_chart(data, output, title=None): + """create a bar chart""" + + bar = Bar(data, tools="pan,wheel_zoom,box_zoom,reset,resize") + bar.filename(output) + bar.width(len(data)*50) + bar.show() + +class BarChartParser(CSVParser): + # TODO: upstream to PlotParser + + def __init__(self, **kwargs): + kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) + kwargs.setdefault('description', __doc__) + CSVParser.__init__(self, **kwargs) + parser.add_argument('-t', '--title', dest='title', + help="plot title") + + +def main(args=sys.argv[1:]): + """CLI""" + + # parse command line + parser = BarChartParser() + options = parser.parse_args(args) + + # parse file + data = pd.read_csv(options.input, header=None, names=options.columns, index_col=0) + + # generate bar chart + bar_chart(data, options.output, title=options.title or options.input.name) + +if __name__ == '__main__': + main() diff -r 1b0854ee78e0 -r 067aa27050a3 numerics/read.py --- a/numerics/read.py Wed Mar 11 18:41:42 2015 -0700 +++ b/numerics/read.py Sun Mar 15 08:28:42 2015 -0700 @@ -2,8 +2,10 @@ # -*- coding: utf-8 -*- """ -read CSV, etc +read CSV """ +# TODO: support other formats + # imports import argparse @@ -13,7 +15,7 @@ from .write import CSVWriter # module globals -__all__ = ['main', 'CSVParser'] +__all__ = ['CSVSchema', 'read_csv', 'CSVParser', 'main'] string = (str, unicode) diff -r 1b0854ee78e0 -r 067aa27050a3 setup.py --- a/setup.py Wed Mar 11 18:41:42 2015 -0700 +++ b/setup.py Sun Mar 15 08:28:42 2015 -0700 @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*-""" + """ setup packaging script for numerics python package """ @@ -16,6 +18,7 @@ from setuptools import setup kw['entry_points'] = """ [console_scripts] + bar-chart = numerics.bar:main cat-columns = numerics.cat_columns:main display-fraction = numerics.text_display:main histogram = numerics.histogram:main