Code Monkey home page Code Monkey logo

bearcart's Introduction

#Bearcart BearCart ###Creating Rickshaw.js visualizations with Python Pandas

Rickshaw.js is a great JavaScript library built on D3 by the folks at Shutterstock for plotting timeseries. Pandas is a great Python library built by a number of outstanding folks in the open source community for creating timeseries. Bear, meet Cart.

Concept

Pandas Series and DataFrames with DatetimeIndex goes in. Rickshaw.js comes out.

Bearcart is a small library for creating Rickshaw visualizations with Pandas timeseries data structures. It has a simple API, a number of plot types, and some really nice legends and tooltips thanks to the folks at Shutterstock.

Bearcart uses Jinja2 templating to create the output, and the files are simple HTML/CSS/JS that can be manipulated after the fact for your application.

Installation

$ pip install bearcart

Getting Started

Let's plot some stocks and make a line chart. Get data with Pandas, make visualization with Bearcart:

import bearcart
import pandas as pd

html_path = r'index.html'
data_path = r'data.json'
js_path = r'rickshaw.min.js'
css_path = r'rickshaw.min.css'


#All of the following import code comes from Wes McKinney's book, Python
#for Data Analysis

import pandas.io.data as web

all_data = {}

for ticker in ['AAPL', 'GOOG']:
    all_data[ticker] = web.get_data_yahoo(ticker, '1/1/2010', '1/1/2013')

price = pd.DataFrame({tic: data['Adj Close']
                      for tic, data in all_data.iteritems()})

vis = bearcart.Chart(price)
vis.create_chart(html_path=html_path, data_path=data_path,
                 js_path=js_path, css_path=css_path)

Line

Go take a look at this bl.ock for the interactive example with the tooltip and legend data selection.

Lets try more companies, and an area plot:

all_data = {}
for ticker in ['AAPL', 'GOOG', 'XOM', 'MSFT', 'INTC', 'YHOO']:
    all_data[ticker] = web.get_data_yahoo(ticker, '1/1/2012', '1/1/2013')
price = pd.DataFrame({tic: data['Adj Close']
                      for tic, data in all_data.iteritems()})

vis = bearcart.Chart(price, plt_type='area')

Area

Interactive version here. Finally, let's make a scatterplot with some custom colors:

df = pd.concat([price['AAPL'], price['GOOG']], axis=1)[:100]

vis = bearcart.Chart(df, plt_type='scatterplot', colors={'AAPL': '#1d4e69',
                                                         'GOOG': '#3b98ca' })

Scatter

Interactive example here.

If you don't want some of the chart features, like the legend, hover, x-axis, etc, you can just pass those parameters as false when defining the chart:

vis = bearcart.Chart(df, hover=False, legend=False)

Bearcart also supports non-timeseries plotting. Just pass x_time=False:

vis = bearcart.Chart(df, plt_type='bar', x_time=False)
vis = bearcart.Chart(df, plt_type='area', x_time=False)

Bar Area

Interactive examples here and here

That's it- a small little library for making nice little interactive timeseries charts. Happy plotting!

Dependencies

Pandas

Jinja2

Numpy

Status

Beta, at least until it gets some use.

Docs

You can read the entire source in 20 minutes. But I needed to learn Sphinx: https://bearcart.readthedocs.org

bearcart's People

Contributors

nipunbatra avatar wrobstory avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.