Guest User

Untitled

a guest
Mar 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. from matplotlib.sankey import Sankey
  5.  
  6.  
  7. plt.rcParams["figure.figsize"] = (15,10)
  8.  
  9.  
  10. system_1 = [
  11. {"label": "1st", "value": 1.00, "orientation": -1},
  12. {"label": "2nd", "value": 0.15, "orientation": -1},
  13. {"label": "3rd", "value": 0.60, "orientation": -1},
  14. {"label": "5th", "value": 0.25, "orientation": -1},
  15. {"label": "6th", "value": 0.25, "orientation": -1},
  16. {"label": "7th", "value": 0.25, "orientation": 1},
  17. {"label": "8th", "value": 0.25, "orientation": 1},
  18. {"label": "9th", "value": 0.25, "orientation": 1},
  19. {"label": "4th", "value": -0.10, "orientation": -1},
  20. ]
  21.  
  22. fig = plt.figure()
  23. ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[], title="Where are all my cows?")
  24. sankey = Sankey(ax=ax, unit="cow")
  25. system_2 = system_1[:4]
  26. # system_2.append({"label": "new", "value": 0.25, "orientation": 1})
  27. system_2.append({"label": "4th", "value": -0.10, "orientation": -1})
  28.  
  29.  
  30. flows = [x["value"] for x in system_1]
  31. labels = [x["label"] for x in system_1]
  32. orientations=[x["orientation"] for x in system_1]
  33. sankey.add(flows=flows,
  34. labels=labels,
  35. label='one',
  36. pathlengths=[1.5,1.5,0.8,.6,.5,.5,.5,.5,1.5],
  37. orientations=orientations,
  38. )
  39.  
  40. sankey.add(flows=[-x["value"] for x in system_2],
  41. labels=[x["label"] for x in system_2],
  42. label='two',
  43. trunklength=1.5,
  44. orientations=[x["orientation"] for x in system_2],
  45. pathlengths=[1.5,1.5,0.8,0.2,1.5],
  46. prior=0,
  47. connect=(8,4)
  48.  
  49. )
  50.  
  51. diagrams = sankey.finish()
  52. diagrams[-1].patch.set_hatch('/')
  53. plt.legend(loc='best')
  54.  
  55.  
  56. plt.show()
Add Comment
Please, Sign In to add comment