import numpy as np
import matplotlib.pyplot as plt
answers = {1:{'p':157,
'b':72,
't':229},
2:{'p':125,
'b':57,
't':182},
3:{'p':39,
'b':7,
't':46},
4:{'p':4,
'b':4,
't':8},
5:{'m':2.4,
't':3.3,
'a':8.2,
'c':4.3,
'f':3.7,
'w':1,
'o':5.3},
6:0,
7:1.25}
from matplotlib.sankey import Sankey
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[])
sankey = Sankey(ax=ax, unit='', offset=0.2, scale=0.02, head_angle=180)
#Public Patch
sankey.add(patchlabel='', facecolor='#4181bb',
flows=[answers[1]['t'],
-answers[2]['t'],
(answers[2]['t']-answers[1]['t'])],
labels=["Reported",
"Valid Crime under Computer Misuse Act",
"Invalid"],
orientations=[0,0,-1])
sankey.add(patchlabel='',
flows=[answers[2]['t'],
-answers[3]['t'],
(answers[3]['t']-answers[2]['t'])],
labels=[None,
None,
"Insufficient Evidence"],
orientations=[0,0,-1], prior=0, connect=(1,0), facecolor='#37c959')
sankey.add(patchlabel='',
flows=[answers[3]['t'],
-answers[4]['t'],
(answers[4]['t']-answers[3]['t'])],
labels=["Charged",
"Resulted in Prosecution",
"Dropped"],
orientations=[0,1,-1], prior=1, connect=(1,0), facecolor='b')
diagrams = sankey.finish()
diagrams[0].texts[0].set_rotation(90) #Reported
diagrams[0].texts[1].set_rotation(90) # Valid
diagrams[2].texts[0].set_rotation(90)
fig.show()