• Stars
    star
    1,415
  • Rank 33,251 (Top 0.7 %)
  • Language
    Python
  • Created over 13 years ago
  • Updated almost 4 years ago

Reviews

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

Repository Details

a plottling library for python, based on D3

Hello

August 2013

Hello! Maybe you're looking for a nice Python interface to build interactive, javascript based plots that look as nice as all those d3 plots you've been seeing lately? Well, this repository is not a bad place to start looking. The code herein was an experiment to see if this approach was a good idea and, if it was, what the experience of plotting into the browser from Python would feel like.

All the code should work, more or less, and you are welcome to fork it, muck about with it, and generally get a taste for what this sort of plotting feels like.

You probably don't want to stop reading here, though. Instead, you should go check out vincent which is a much nicer take on this idea, created using vega, and is in general a much more gentlemanly way to go about this sort of thing. It's also being properly updated and developed, unlike the code below.

d3py

This is d3py: a plotting library for python based on d3. The aim of d3py is to provide a simple way to plot data from the command line or simple scripts into a browser window.

d3py accomplishes this by building on two excellent packages. The first is d3.js (Mike Bostock), which is a javascript library for creating data driven documents, which allows us to place arbitrary svg into a browser window. The second is the pandas Python module (Wes Mckinney), which blesses Python with (amongst other things) the DataFrame data structure.

The idioms used to plot data are very simple, and borrow from R's ggplot2 (Hadley Wickham) and Python's matplotlib (John Hunter et al).

Install d3py and dependencies:

  1. easy_install https://github.com/mikedewar/d3py/tarball/master
  2. pip install pandas
  3. pip install numpy
  4. pip install networkx

Example:

  1. create a PandasFigure object around a DataFrame (or a NetworkXFigure object around a Graph)
  2. add geoms to the figure object to plot specific combinations of columns of the data frame.
  3. show the figure, which serves up the figure in a browser window
  4. muck about with the style of the plot using the browser's developer tools
  5. share FTW!

Each geom takes as parameters an appropriate number of column names of the data frame as arguments. For example the Line geom, which has two dimensions, takes an x-value and a y-value. A Point geom, which makes up a scatter plot, has three dimensions and so takes three parameters: x, y and colour (in the future it could take size, too!).

Each geom is styled using css which you can pass in arbitrarily. So, for example, the Point geom comes with a bunch of default styles, but you can also specify fill=red as a keyword argument which will add a custom css line for that set of points which will turn them red. This also means you can style the plot live in the browser using Firebug in Firefox or Chrome's developer tools.

d3py aims to create really simple javascript source code wherever possible, so you can go in and edit the plots to embed them into your own sites if needs be. The .show() method writes an html file containing the basic markup, a css file with the styles for each geom, a json file with the data from the Figure's DataFrame and a js file with the d3 code in it. The strings that generate the js and css files can always be pulled from the Figure object so you can see how d3py builds up your graph.

An example session could like:

import d3py
import pandas
import numpy as np
	
# some test data
T = 100
# this is a data frame with three columns (we only use 2)
df = pandas.DataFrame({
    "time" : range(T),
    "pressure": np.random.rand(T),
    "temp" : np.random.rand(T)
})
## build up a figure, ggplot2 style
# instantiate the figure object
fig = d3py.PandasFigure(df, name="basic_example", width=300, height=300) 
# add some red points
fig += d3py.geoms.Point(x="pressure", y="temp", fill="red")
# writes 3 files, starts up a server, then draws some beautiful points in Chrome
fig.show() 

Check out the examples in the folder for more functionality! Assuming everything is working OK, the examples should generate (something akin to) the following plots:

point

point example

line

line example

bar

bar example

area

area example

More Repositories

1

d3talk

baby steps in d3.js
JavaScript
173
star
2

getting_started_with_d3

This is the code repository for the book "Getting Started With D3"
Python
83
star
3

Iraq-War-Diary-Analysis

An analysis of the Iraq War Diary released by wikileaks in October 2010
14
star
4

pyLDS

A Python module for performing learning and inference in Linear Dynamic Systems
Python
13
star
5

EDHMM

An implementation of the Explicit Duration HMM using Python
Python
12
star
6

BrainIDE

An implementation of the IntegroDifference Equation for EEG data
TeX
10
star
7

monitorama_d3

introductory workshop talk for monitorama about using d3 to monitor bitly clicks
Python
8
star
8

beatingheart

the beating heart of kim kardashian
JavaScript
5
star
9

Biosurvey

Biosurveillance with Ad-Hoc observations
Python
4
star
10

autoproxy

an etcd backed automatic nginx reverse proxy
Go
4
star
11

Biomarker

Identification of Biomarkers from microarray
R
4
star
12

nsq_monitor

Monitors an NSQ Topic, providing some information about the data inside that topic
JavaScript
4
star
13

picorna

classifying viruses
Python
3
star
14

RealTimeStorytelling

code for COMS E6998.004
Python
3
star
15

batchAggregator

like the streaming one, just on a file
Go
2
star
16

EDHMM_SPL

write up of the Explicit Duration HMM for signal processing letters
Python
2
star
17

CourtshipIndex

A paper describing the automatic extraction of an enhanced courtship measure
Python
2
star
18

fireflymap

experiments with visualising spatiotemporal data in real time
JavaScript
2
star
19

codeneuro_streamtools

some little files for my streamtools presentation at code neuro NYC 2015
Shell
2
star
20

streamscope

visualise streams of data through a websocket
JavaScript
2
star
21

session-features

build machine learning features by combining events into sessions, and then aggregating over events in a session
2
star
22

immgen

some basic tools to access and normalise the IMMGEN arrays available from GEO
Python
2
star
23

hackny_talk

a talk about measuring attention for hack NY
JavaScript
2
star
24

resume

my resume
TeX
2
star
25

PythonPointProcesses

basic tools for dealing with point proceses in Python and pandas
Python
2
star
26

HIDEX

Paper and code associated with the HIDEX(p,q) model
Python
2
star
27

neurons

Code to infer the connectivity structure of neurons from observations of calcium
Python
1
star
28

rf-immanence

experiments with a cheap software defined radio receiver
Go
1
star
29

d3go

generate d3 graphics from golang
1
star
30

graphLearning

trying to learn goblin/gremlin/titan
Python
1
star
31

DG-Badger

generate a large graph and store it in an badger DB
Go
1
star
32

go-sqsReader

a golang SQS reader
Go
1
star
33

quadcopter

3D printable parts for a quadcopter
1
star
34

csvTokenise

a quick command line program for tokenising a column in a csv file
Go
1
star
35

nsq-docker

dockerfiles for nsq
Shell
1
star
36

ThePercyProtocol

The Protocol For Lord Percival Smith Hastings, Destroyer of Worlds
1
star
37

fpeService

a service that encrypts your PII using format preserving encryption
Go
1
star
38

go-metropolis

an entirely unfinshed metropolis hastings algorithm
Go
1
star
39

mobilizing_health_d3

a talk about using d3 to sketch mobilizing health data
JavaScript
1
star