SlideShare a Scribd company logo
Making Stream Graphs with
                           Python

                                   Nathan Bergey


                                   April 29, 2010



Nathan Bergey
Making Stream Graphs with Python
Starting Point



                 I said “Hey, I can do that”
                 Then, later, I did that




Nathan Bergey
Making Stream Graphs with Python
Python and Paper



                 Working with Python was easy.
                 http://leebyron.com/else/streamgraph/




Nathan Bergey
Making Stream Graphs with Python
Stacked Graphs




Nathan Bergey
Making Stream Graphs with Python
Move it down

       Start at with g0 being some number other than 0.




Nathan Bergey
Making Stream Graphs with Python
Symmetry




Nathan Bergey
Making Stream Graphs with Python
A Simple Algorithm
                                              n
                                          1
                                   g0 = −           fi
                                          2   i=1




Nathan Bergey
Making Stream Graphs with Python
A More Complex Algorithm
                                           n
                                      1
                              g0 = −             (n − i + 1)fi
                                     n+1   i=1




Nathan Bergey
Making Stream Graphs with Python
Comparison




Nathan Bergey
Making Stream Graphs with Python
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
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
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
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
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
A Single Shape




Nathan Bergey
Making Stream Graphs with Python
Labeling


                 Not actually possible?
                 Packing algorithms

                 Make some random boxes
                 Keep the largest one




Nathan Bergey
Making Stream Graphs with Python
SVG


                 Using SVGFig
                 http://code.google.com/p/svgfig/
                 Could be better
                 Custom interpolation?




Nathan Bergey
Making Stream Graphs with Python
Resources


                 Me: @natronics
                 pystreamgraph:
                 http://github.com/natronics/pystreamgraph




Nathan Bergey
Making Stream Graphs with Python

More Related Content

PDF
Data Visualization in Python
PDF
Data Analysis and Visualization using Python
PPT
chapter - 6.ppt
PPTX
Histogram of Image Colors
PPT
Lec 17 heap data structure
PPTX
2 cs xii_python_functions _ scopes
PPTX
Essential NumPy
Data Visualization in Python
Data Analysis and Visualization using Python
chapter - 6.ppt
Histogram of Image Colors
Lec 17 heap data structure
2 cs xii_python_functions _ scopes
Essential NumPy

Recently uploaded (20)

PPTX
EABDM Slides for Indifference curve.pptx
PDF
financing insitute rbi nabard adb imf world bank insurance and credit gurantee
PDF
discourse-2025-02-building-a-trillion-dollar-dream.pdf
PDF
way to join Real illuminati agent 0782561496,0756664682
PDF
THE EFFECT OF FOREIGN AID ON ECONOMIC GROWTH IN ETHIOPIA
PPT
E commerce busin and some important issues
PDF
how_to_earn_50k_monthly_investment_guide.pdf
PDF
Mathematical Economics 23lec03slides.pdf
PDF
NAPF_RESPONSE_TO_THE_PENSIONS_COMMISSION_8 _2_.pdf
PPTX
Introduction to Managemeng Chapter 1..pptx
PDF
Predicting Customer Bankruptcy Using Machine Learning Algorithm research pape...
PDF
Copia de Minimal 3D Technology Consulting Presentation.pdf
PDF
How to join illuminati agent in Uganda Kampala call 0782561496/0756664682
PDF
ECONOMICS AND ENTREPRENEURS LESSONSS AND
PPTX
Unilever_Financial_Analysis_Presentation.pptx
PPTX
introuction to banking- Types of Payment Methods
PDF
final_dropping_the_baton_-_how_america_is_failing_to_use_russia_sanctions_and...
PPTX
How best to drive Metrics, Ratios, and Key Performance Indicators
PPTX
4.5.1 Financial Governance_Appropriation & Finance.pptx
PPTX
Who’s winning the race to be the world’s first trillionaire.pptx
EABDM Slides for Indifference curve.pptx
financing insitute rbi nabard adb imf world bank insurance and credit gurantee
discourse-2025-02-building-a-trillion-dollar-dream.pdf
way to join Real illuminati agent 0782561496,0756664682
THE EFFECT OF FOREIGN AID ON ECONOMIC GROWTH IN ETHIOPIA
E commerce busin and some important issues
how_to_earn_50k_monthly_investment_guide.pdf
Mathematical Economics 23lec03slides.pdf
NAPF_RESPONSE_TO_THE_PENSIONS_COMMISSION_8 _2_.pdf
Introduction to Managemeng Chapter 1..pptx
Predicting Customer Bankruptcy Using Machine Learning Algorithm research pape...
Copia de Minimal 3D Technology Consulting Presentation.pdf
How to join illuminati agent in Uganda Kampala call 0782561496/0756664682
ECONOMICS AND ENTREPRENEURS LESSONSS AND
Unilever_Financial_Analysis_Presentation.pptx
introuction to banking- Types of Payment Methods
final_dropping_the_baton_-_how_america_is_failing_to_use_russia_sanctions_and...
How best to drive Metrics, Ratios, and Key Performance Indicators
4.5.1 Financial Governance_Appropriation & Finance.pptx
Who’s winning the race to be the world’s first trillionaire.pptx
Ad
Ad

Stream Graphs with Python

  • 1. Making Stream Graphs with Python Nathan Bergey April 29, 2010 Nathan Bergey Making Stream Graphs with Python
  • 2. Starting Point I said “Hey, I can do that” Then, later, I did that Nathan Bergey Making Stream Graphs with Python
  • 3. Python and Paper Working with Python was easy. http://leebyron.com/else/streamgraph/ Nathan Bergey Making Stream Graphs with Python
  • 4. Stacked Graphs Nathan Bergey Making Stream Graphs with Python
  • 5. Move it down Start at with g0 being some number other than 0. Nathan Bergey Making Stream Graphs with Python
  • 7. A Simple Algorithm n 1 g0 = − fi 2 i=1 Nathan Bergey Making Stream Graphs with Python
  • 8. A More Complex Algorithm n 1 g0 = − (n − i + 1)fi n+1 i=1 Nathan Bergey Making Stream Graphs with Python
  • 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. 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. 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. 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. 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. A Single Shape Nathan Bergey Making Stream Graphs with Python
  • 16. Labeling Not actually possible? Packing algorithms Make some random boxes Keep the largest one Nathan Bergey Making Stream Graphs with Python
  • 17. SVG Using SVGFig http://code.google.com/p/svgfig/ Could be better Custom interpolation? Nathan Bergey Making Stream Graphs with Python
  • 18. Resources Me: @natronics pystreamgraph: http://github.com/natronics/pystreamgraph Nathan Bergey Making Stream Graphs with Python