Advertisement
Guest User

Untitled

a guest
Oct 9th, 2022
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | Software | 0 0
  1. from floweaver import *
  2. import pandas as pd
  3.  
  4. # Set the default size to fit the documentation better.
  5. size = dict(width=570, height=300)
  6.          
  7. d = [
  8.      {'source':'Brain', 'target': 'Brain', 'type':'1', 'value':1},
  9.      {'source':'Heart', 'target': 'Heart', 'type':'2', 'value':1},
  10.      {'source':'Banana', 'target': 'Banana', 'type':'3', 'value':1},
  11.      {'source':'Lung', 'target': 'Lung', 'type':'4', 'value':1},
  12.      {'source':'Skin', 'target': 'Skin', 'type':'5', 'value':1},
  13.     ]
  14.  
  15. flows = pd.DataFrame(data=d)
  16.  
  17. nodes = {
  18.     't1': ProcessGroup(['Brain', 'Heart', 'Lung', '']),
  19.     #'t2': ProcessGroup(['Heart', 'Brain', 'Banana']),
  20.     #'t3': ProcessGroup(['Banana', 'Heart', 'Brain']),
  21.     't4': ProcessGroup(['Lung', 'Skin', 'Brain', 'Heart', 'Banana']),
  22. }
  23.  
  24. nodes['t1'].partition = Partition.Simple('process', ['Brain', 'Heart', 'Lung'])
  25. nodes['t2'] = Waypoint(Partition.Simple('process', ['Heart', 'Lung', 'Brain']))
  26. # Can I group 2 process groups for T3?
  27. nodes['t3'] = Waypoint(Partition.Simple('process', ['Banana', 'Skin' 'Heart', 'Lung' 'Brain']))
  28. nodes['t4'].partition = Partition.Simple('process', ['Lung', 'Brain', 'Heart', 'Banana'])
  29.  
  30. nodes['t2_1'] = ProcessGroup(['Skin'], partition=Partition.Simple('process', ['Skin']))
  31. nodes['t2_2'] = ProcessGroup(['Banana'], partition=Partition.Simple('process', ['Banana']))
  32.  
  33. ordering = [
  34.     [['t1']],      
  35.     [['t2_1'], ['t2'], ['t2_2']],
  36.     [['t3']],
  37.     [['t4']],
  38. ]
  39.  
  40. bundles = [
  41.     Bundle('t1', 't4', waypoints=['t2', 't3']),
  42.     Bundle('t2_1', Elsewhere, waypoints=['t3']),
  43.     Bundle('t2_2', 't4', waypoints=['t3'])
  44. ]
  45.  
  46. df = pd.DataFrame(d)
  47.  
  48. ranks = Partition.Simple("type", df.type.unique())
  49.  
  50. sdd = SankeyDefinition(nodes, bundles, ordering, flow_partition=ranks)
  51. weave(sdd, df).to_widget(**size)
  52. weave(sdd, df).to_widget(**size).auto_save_png('./flow-3-example.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement