Skip to content
mynameisfiber edited this page Feb 20, 2012 · 3 revisions

This page documents our noodling about with thoughts about the idiom. The aim is to be ggplot-like, though we're definitely not making a rigid copy. We are also trying to follow the d3-esque idea of exposing the user directly to CSS, so we make every attempt for the user to pass in css as keyword-arguments. We're also trying to remain flexible - we're going to need to be able to take into account interaction and animation, which is a pretty new concept for exploratory data analysis.

With

Right now the basic idiom goes like

f = Figure(data)
f += geom(x=colname_x, y=colname_y)
f.show()

Behind all this we're creating a JSON from the pandas data frame, creating an HTML page, some javascript and CSS and then instantiated a webserver to go ahead and serve all this stuff. Managing the setup and tear down of this can get a little hairy so Micha has suggested we use the with statement.

with Figure(data) as f:
    f += geom(x=colname_x, y=colname_y)
    f.show()

The with function would work, in this case, by blessing the Figure object with enter and exit methods. The enter method would instantiate the figure and ready the temporary files and whatnot. f.show() would cause the files to be written, the server to be started and maybe talks to the web browser.

The exit method would be a bit trickier though. One aim for d3py is that we should be able to use it for interactive use, so we want to be able to muck about and add more geoms to our heart's content. So the with statement's exit function maybe shouldn't tear down the server or delete files, because we might want to do some more analysis and then add things to the plot later on.

Having said that, it would be lovely to have the with statement turn off the server and delete all the files because otherwise it can get to be a bit of a mess...?

micha: I think having with compatability is a good thing. The only problem is that in interactive code, the user won't always be inside of the with block. This only leads to no cleanup in that subset of interactive usage, which I think is fine. So basically, I'm all for this!

Axes Objects

The proposed idiom for axes is to add them like a geom:

f = Figure(data)
f += Line(x=x, y=y)
f += Axes(x=x, y=y)

This could be broken down into

f = Figure(data)
f += Line(x=x, y=y)
f += xAxis(x)
f += yLogAxis(y)

This kind of idiom provides a lot of control - we don't have to mess about with matlab-style semilogy sort of commands. But, as it stands, it means we don't get any automatic axes which you would with, say, matlab/matplotlib/ggplot. The awkwardness of the axes is that they depend on the scales used in the plot, of which there might be many. It's not immediately obvious which scales should be used especially if we're not enforcing consistency in the plot, ggplot style.

Clone this wiki locally