• Stars
    star
    267
  • Rank 152,729 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 11 years ago
  • Updated almost 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Creating Rickshaw.js visualizations with Python Pandas

#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

More Repositories

1

vincent

A Python to Vega translator
Python
2,038
star
2

sticky

IPython Notebook + D3
Python
128
star
3

pydataseattle2015

PyData Seattle 2015: Python Data Bikeshed
127
star
4

mcflyin

A small timeseries transformation API built on Flask and Pandas
Python
85
star
5

PythonToScala

A short guide for transitioning from Python to Scala
65
star
6

malort

JSON -> Relational DB Column Types
Python
64
star
7

vincent_map_data

A geodata repository for Vincent examples
63
star
8

pelican_dynamic

Easily embed custom JS and CSS in your Pelican blog articles
Python
52
star
9

climatic

A small toolbox of wind data analysis plotting tools
Python
43
star
10

pdxpython2015

Portland Python Meetup March 2015
41
star
11

pydatasv2014

PyData Silicon Valley 2014 Code + Presentation
CSS
37
star
12

pgshift

Postgres pg_dump -> Redshift
Python
35
star
13

vldb2015

Notes from VLDB conference
30
star
14

d3.chart.choropleth

A d3.chart based choropleth map
JavaScript
26
star
15

redifest

Generate a Redshift .manifest file for a given S3 bucket
Python
21
star
16

pdxdatasci2014

PDX Data Science Meetup November 2014
CSS
12
star
17

DataEngArchSimple

PDX Data Science Meetup March 2016 Presentation
10
star
18

zipwhich

Comparing different zip code datasets
10
star
19

notebook-styles

IPython notebook styles
9
star
20

portlandmapdemo

Creating and Publishing Maps with D3, Dymo, and PhantomJS
JavaScript
7
star
21

reconciler

Reconcile S3 and Redshift
Python
4
star
22

caladan

Tabular Analytics with Clojure
Clojure
4
star
23

ds4ds_2015

Data Structures for Data Science 2015 Slides
3
star
24

yoflask

CSS
2
star
25

tumalo

Clojure Elasticsearch tools
Clojure
2
star
26

wrobstory.github.com

Static blog powered by Pelican
CSS
2
star
27

vegalite-pojo

Generating POJOs from the vega-lite spec
Java
1
star
28

feint

Python
1
star
29

strangeloop_2015

Strangeloop After Strangeloop
1
star