13

I am new to Python and have worked my way through a few books on it. Everything is great, except visualizations. I really dislike matplotlib and Bokeh requires too heavy of a stack.

The workflow I want is:

Data munging analysis using pandas in ipython notebook -> visualization using d3 in sublimetext2

However, being new to both Python and d3, I don't know the best way to export my pandas dataframe to d3. Should I just have it as a csv? JSON? Or is there a more direct way?

Side question: Is there any (reasonable) way to do everything in an ipython notebook instead of switching to sublimetext?

Any help would be appreciated.

tmthydvnprt
  • 10,398
  • 8
  • 52
  • 72
Anton
  • 4,765
  • 12
  • 36
  • 50
  • 2
    There's `df.to_json` or `df.to_csv` for moving the data around. There's [vincent](https://github.com/wrobstory/vincent) for a python -> vega translator (it supports DataFrames well). And another project of Rob's, [sticky](https://github.com/wrobstory/sticky), is in alpha, but it sounds like what you want for not leaving the IPython notebook. – TomAugspurger May 14 '14 at 16:28
  • I know you said you dislike matplotlib, but have you looked at [mpld3](http://mpld3.github.io)? It's quite nice, I've had a recent success using it to make an online interactive plot. – Elias Dorneles May 14 '14 at 17:00

2 Answers2

5

Basically there is no best format what will fit all your visualization needs.

It really depends on the visualizations you want to obtain.

For example, a Stacked Bar Chart takes as input a CSV file, and an adjacency matrix vizualisation takes a JSON format.

From my experience:

  • to display relations beetween items, like adjacency matrix or chord diagram, one will prefer a JSON format that will allow to describe only existing relations. Data are stored like in a sparse matrix, and several data can be nested using dictionary. Moreover this format can directly be parsed in Python.
  • to display properties of an array of items, a CSV format can be fine. A perfect example can be found here with a parallel chart display.
  • to display hierarchical data, like a tree, JSON is best suited.

The best thing to do to help you figure out what best format you need, is to have a look at this d3js gallery

Guillaume Jacquenot
  • 11,217
  • 6
  • 43
  • 49
1

You can use D3 directly inside of Jupyter / Ipython. Try the two links below ..

http://blog.thedataincubator.com/2015/08/embedding-d3-in-an-ipython-notebook/

https://github.com/cmoscardi/embedded_d3_example/blob/master/Embedded_D3.ipynb

ashishsingal
  • 2,810
  • 3
  • 18
  • 26