Skip to main content

Python Pandas + Rickshaw.js = BearCart

Project description

###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.

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.

$ 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 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)

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')


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' })

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)

Interactive examples [here]( and [here](

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



Beta, at least until it gets some use.

You can read the entire source in 20 minutes. But I needed to learn Sphinx:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for bearcart, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size bearcart-0.1.1.tar.gz (22.7 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page