I'm working on a Sankey diagram and I'm experiencing some issues with the labeling process. Is there a way to put the labels and the values of each flow on the same line? I would like them to look like this: "Label: value".
Here are the code and the resulting diagram.
from matplotlib import pyplot as plt
from matplotlib.sankey import Sankey
fig = plt.figure(figsize=(8.3, 11.7))
ax = fig.add_subplot(1, 1, 1)
plt.axis('off')
# these will be provided soon
# Input = ...
# L0 = ...
# L1, L2, L3, L4, L5, L6, L7, L8, L9 = ...
# F9 = ...
sankey = Sankey(ax=ax,
scale=1 / Input,
offset=0.6,
head_angle=135,
shoulder=0,
gap=0.2,
radius=0.1,
format='%.1f',
unit='%')
s0 = sankey.add(flows=[Input, -L0, -(Input - L0)],
labels=['Input 1', 'Loss 0', ''],
orientations=[0, 1, 0],
trunklength=1,
rotation=-90,
fc='crimson', alpha=0.8)
s1 = sankey.add(flows=[Input - L0, -L1, -L2, -L3, -L4, -L5, -L6, -L7, -L8, -L9, -F9],
labels=['Input 2', 'Loss 1', 'Loss 2', 'Loss 3', 'Loss 4', 'Loss 5', 'Loss 6', 'Loss 7', 'Loss 8',
'Loss 9', 'Output'],
orientations=[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
trunklength=1,
rotation=-90,
prior=0, connect=(2, 0),
fc='crimson', alpha=0.6)
diagrams = sankey.finish()
for d in diagrams:
for t in d.texts:
t.set_fontsize(10)
t.set_horizontalalignment('center')
t.set_verticalalignment('center')
diagrams[0].texts[0].set_position(xy=[0, 0.4])
diagrams[0].texts[2].set_position(xy=[10, 10])
plt.show()
Sankey diagram