The concept of “stream graphs” were widely popularized by the New York Times when they published a now famous graphic of box office numbers over time using a stream graph, which is a stacked area graph that is displaced around the x-axis to make an organic flowing shape.
I think I first saw a stream graph that Amber Case was showing off after coming back from a conference. She was using a web based app that someone had wrote that graphed the most used words on twitter about a particular search term.
Use Case: Twitter
Another place where there is lots of volatile data is twitter. In fact several years ago someone wrote a program to search the last 1000 tweets containing some search term and then draw a graph showing words inside those tweets popularity over time. The result was surprisingly effective at showing conferences because the graph would grow and shrink roughly in proportion with how good a speaker was, and what he or she said that was most interesting.
In general stream graphs are good for any kind of bin-able data that evolves complexly over time.
The Problem
The problem with the web app Amber was using is that it's pretty limited. There is no way to go further back than the last 1000 tweets and any data that is collected is immediately graphed, instead of being saved for further breaking down and analysis. Plus there is no way to change the colors or scaling.
I wanted to help. It took me a while to figure out where to start. Eventually I found a paper filled with wonderful mathematical descriptions of how to draw stream graphs. And at the same time I discovered how easy it is to write in python. So I wrote a simple python class that would take some arbitrary set of data (a list of a list of points) and draw a pretty stream graph in SVG.
You can too!
Amber's friend Aaron Parecki is a Portland based developer who took my stream graph class and, using his twitter API key and database skills, finally fix Amber's conference graphing woes. I open sourced my code at github where you too can start making stream graphs of your own out of any data you want.
Amber, Aaron and I presented an overview of our work at the Portland DataViz users group in Portland, Oregon on April 29th. You can see the slides to my part of the talk here:


Science Hack Days – Ideas to Things
ISS Notify
Watching a Shuttle Launch
Aquila Glass School
2 Comments
Hi there:
I found this blofg while searching in Google amd Bing about visualizations and your code is the simplest I have encountered after going to github and downloading your code for a streamgraph , but I don’t understand how to make it work.
Is it possible for you to send me the source code and a streamgrapgh of something simple that you’ve done ? ( a couple of labels and timeframes in the x axis that kind of sample ) I am sure that if I see the code of an example and it’s results I might know how to understand the rest.
Thank you for your attention and hope you can guide me
FJ Caceres
Unfortunately I haven’t had much time to work on this project recently, so it’s still pretty rough around the edges.
There should be a test.py file in the git repo that makes a simple example graph when you run it.
The basic use is you take some data and bin it so that every layer has the same number of points and put them into lists. For example lets say I had data like this:
1,4 2,6 3,3 and
1,3, 2,0 3,6 etc.
Where those lines are lists of x,y coordinates. Then I would zip them into lists
layer1 = [(1,4), (2,6), (3,3)]
layer2 = [(1,3).....] etc.
Then put the layers into a big list
data = [layer1, layer2....]
This should actually be pretty easy to do with existing data and some for loops.
Then all you have to do is pass the data list to the library and it will make a graph!
sg = pystreamgraph.StreamGraph(data, colors=colors, labels=labels)
sg.draw(“Theme_River.test.svg”, “Theme_River”)
The color and label lists are simple lists of colors and labels, ex:
colors = (#ffcc22, #ffffbb,…..)
labels = (“One”, “Two”…)
I hope that helps. And I would encourage looking through the code, hopefully it’s not too hard to read. If you have any fixes let me know.