Upcoming SlideShare
×

# Stream Graphs with Python

6,478 views
6,178 views

Published on

Published in: Economy & Finance
3 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
6,478
On SlideShare
0
From Embeds
0
Number of Embeds
2,913
Actions
Shares
0
21
0
Likes
3
Embeds 0
No embeds

No notes for slide

### Stream Graphs with Python

1. 1. Making Stream Graphs with Python Nathan Bergey April 29, 2010 Nathan Bergey Making Stream Graphs with Python
2. 2. Starting Point I said “Hey, I can do that” Then, later, I did that Nathan Bergey Making Stream Graphs with Python
3. 3. Python and Paper Working with Python was easy. http://leebyron.com/else/streamgraph/ Nathan Bergey Making Stream Graphs with Python
4. 4. Stacked Graphs Nathan Bergey Making Stream Graphs with Python
5. 5. Move it down Start at with g0 being some number other than 0. Nathan Bergey Making Stream Graphs with Python
6. 6. Symmetry Nathan Bergey Making Stream Graphs with Python
7. 7. A Simple Algorithm n 1 g0 = − fi 2 i=1 Nathan Bergey Making Stream Graphs with Python
8. 8. A More Complex Algorithm n 1 g0 = − (n − i + 1)fi n+1 i=1 Nathan Bergey Making Stream Graphs with Python
9. 9. Comparison Nathan Bergey Making Stream Graphs with Python
10. 10. pystreamgraph http://github.com/natronics/pystreamgraph Takes a list of a list of data points. You provide Colors, Labels, etc. Draws it, but with some options Nathan Bergey Making Stream Graphs with Python
11. 11. Preprocess Calculate the sum of the y values for i in range(0, n_points): y_sum = 0 for layer in range(0, n_layers): y_sum += data[layer][i][1] y_extent.append(y_sum) Nathan Bergey Making Stream Graphs with Python
12. 12. Step 1 Calculate g0 g_0 = [] for i in range(n_points): g_0.append(- y_extent[i] / 2.0) Nathan Bergey Making Stream Graphs with Python
13. 13. Draw it for layer in range(n_layers): points = [] point_range = range(n_points) for i in point_range: x = data[layer][i][0] y = data[layer][i][1] y_stacked = g_0[i] + y for l in range(layer): y_stacked += self.data[l][i][1] points.append((x, y_stacked)) Nathan Bergey Making Stream Graphs with Python
14. 14. Draw it point_range.reverse() for i in point_range: x = self.data[layer][i][0] y_stacked = g_0[i] for l in range(layer): y_stacked += self.data[l][i][1] points.append((x,y_stacked)) Nathan Bergey Making Stream Graphs with Python
15. 15. A Single Shape Nathan Bergey Making Stream Graphs with Python
16. 16. Labeling Not actually possible? Packing algorithms Make some random boxes Keep the largest one Nathan Bergey Making Stream Graphs with Python
17. 17. SVG Using SVGFig http://code.google.com/p/svgﬁg/ Could be better Custom interpolation? Nathan Bergey Making Stream Graphs with Python
18. 18. Resources Me: @natronics pystreamgraph: http://github.com/natronics/pystreamgraph Nathan Bergey Making Stream Graphs with Python