changeset 103:067aa27050a3

limping along towards bar charts
author Jeff Hammel <k0scist@gmail.com>
date Sun, 15 Mar 2015 08:28:42 -0700
parents 1b0854ee78e0
children 889728b8d359
files numerics/bar.py numerics/read.py setup.py
diffstat 3 files changed, 64 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- /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()
--- 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)
 
 
--- 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