SlideShare a Scribd company logo
1 of 18
Download to read offline
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

Recently uploaded

Law of Demand.pptxnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Law of Demand.pptxnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnLaw of Demand.pptxnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Law of Demand.pptxnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
TintoTom3
 
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
Health
 
abortion pills in Riyadh Saudi Arabia (+919707899604)cytotec pills in dammam
abortion pills in Riyadh Saudi Arabia (+919707899604)cytotec pills in dammamabortion pills in Riyadh Saudi Arabia (+919707899604)cytotec pills in dammam
abortion pills in Riyadh Saudi Arabia (+919707899604)cytotec pills in dammam
samsungultra782445
 
abortion pills in Jeddah Saudi Arabia (+919707899604)cytotec pills in Riyadh
abortion pills in Jeddah Saudi Arabia (+919707899604)cytotec pills in Riyadhabortion pills in Jeddah Saudi Arabia (+919707899604)cytotec pills in Riyadh
abortion pills in Jeddah Saudi Arabia (+919707899604)cytotec pills in Riyadh
samsungultra782445
 

Recently uploaded (20)

Lion One Corporate Presentation May 2024
Lion One Corporate Presentation May 2024Lion One Corporate Presentation May 2024
Lion One Corporate Presentation May 2024
 
Pension dashboards forum 1 May 2024 (1).pdf
Pension dashboards forum 1 May 2024 (1).pdfPension dashboards forum 1 May 2024 (1).pdf
Pension dashboards forum 1 May 2024 (1).pdf
 
劳伦森大学毕业证
劳伦森大学毕业证劳伦森大学毕业证
劳伦森大学毕业证
 
Group 8 - Goldman Sachs & 1MDB Case Studies
Group 8 - Goldman Sachs & 1MDB Case StudiesGroup 8 - Goldman Sachs & 1MDB Case Studies
Group 8 - Goldman Sachs & 1MDB Case Studies
 
Law of Demand.pptxnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Law of Demand.pptxnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnLaw of Demand.pptxnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
Law of Demand.pptxnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 
Stock Market Brief Deck (Under Pressure).pdf
Stock Market Brief Deck (Under Pressure).pdfStock Market Brief Deck (Under Pressure).pdf
Stock Market Brief Deck (Under Pressure).pdf
 
cost-volume-profit analysis.ppt(managerial accounting).pptx
cost-volume-profit analysis.ppt(managerial accounting).pptxcost-volume-profit analysis.ppt(managerial accounting).pptx
cost-volume-profit analysis.ppt(managerial accounting).pptx
 
Business Principles, Tools, and Techniques in Participating in Various Types...
Business Principles, Tools, and Techniques  in Participating in Various Types...Business Principles, Tools, and Techniques  in Participating in Various Types...
Business Principles, Tools, and Techniques in Participating in Various Types...
 
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
+971565801893>>SAFE ORIGINAL ABORTION PILLS FOR SALE IN DUBAI,RAK CITY,ABUDHA...
 
Shrambal_Distributors_Newsletter_May-2024.pdf
Shrambal_Distributors_Newsletter_May-2024.pdfShrambal_Distributors_Newsletter_May-2024.pdf
Shrambal_Distributors_Newsletter_May-2024.pdf
 
Female Escorts Service in Hyderabad Starting with 5000/- for Savita Escorts S...
Female Escorts Service in Hyderabad Starting with 5000/- for Savita Escorts S...Female Escorts Service in Hyderabad Starting with 5000/- for Savita Escorts S...
Female Escorts Service in Hyderabad Starting with 5000/- for Savita Escorts S...
 
FE Credit and SMBC Acquisition Case Studies
FE Credit and SMBC Acquisition Case StudiesFE Credit and SMBC Acquisition Case Studies
FE Credit and SMBC Acquisition Case Studies
 
falcon-invoice-discounting-unlocking-prime-investment-opportunities
falcon-invoice-discounting-unlocking-prime-investment-opportunitiesfalcon-invoice-discounting-unlocking-prime-investment-opportunities
falcon-invoice-discounting-unlocking-prime-investment-opportunities
 
Significant AI Trends for the Financial Industry in 2024 and How to Utilize Them
Significant AI Trends for the Financial Industry in 2024 and How to Utilize ThemSignificant AI Trends for the Financial Industry in 2024 and How to Utilize Them
Significant AI Trends for the Financial Industry in 2024 and How to Utilize Them
 
Mahendragarh Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Mahendragarh Escorts 🥰 8617370543 Call Girls Offer VIP Hot GirlsMahendragarh Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
Mahendragarh Escorts 🥰 8617370543 Call Girls Offer VIP Hot Girls
 
Certified Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil ba...
Certified Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil ba...Certified Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil ba...
Certified Kala Jadu, Black magic specialist in Rawalpindi and Bangali Amil ba...
 
In Sharjah ௵(+971)558539980 *_௵abortion pills now available.
In Sharjah ௵(+971)558539980 *_௵abortion pills now available.In Sharjah ௵(+971)558539980 *_௵abortion pills now available.
In Sharjah ௵(+971)558539980 *_௵abortion pills now available.
 
abortion pills in Riyadh Saudi Arabia (+919707899604)cytotec pills in dammam
abortion pills in Riyadh Saudi Arabia (+919707899604)cytotec pills in dammamabortion pills in Riyadh Saudi Arabia (+919707899604)cytotec pills in dammam
abortion pills in Riyadh Saudi Arabia (+919707899604)cytotec pills in dammam
 
abortion pills in Jeddah Saudi Arabia (+919707899604)cytotec pills in Riyadh
abortion pills in Jeddah Saudi Arabia (+919707899604)cytotec pills in Riyadhabortion pills in Jeddah Saudi Arabia (+919707899604)cytotec pills in Riyadh
abortion pills in Jeddah Saudi Arabia (+919707899604)cytotec pills in Riyadh
 
NO1 Verified Online Love Vashikaran Specialist Kala Jadu Expert Specialist In...
NO1 Verified Online Love Vashikaran Specialist Kala Jadu Expert Specialist In...NO1 Verified Online Love Vashikaran Specialist Kala Jadu Expert Specialist In...
NO1 Verified Online Love Vashikaran Specialist Kala Jadu Expert Specialist In...
 

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

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