matplotlib 桑基图中的连接流程

2024-02-29

我正在使用 matplotlibssankey功能,并且在连接两个流时存在问题。基本上,我只想连接流程Qab,rekup到流的末尾Qzu,rekup(参见屏幕截图)。

似乎很容易,但我仍然不知道如何管理它。

Here's the screenshot: https://www.dropbox.com/s/2satz9ryniy958v/Sankey.png?dl=0 https://www.dropbox.com/s/2satz9ryniy958v/Sankey.png?dl=0 enter image description here Here's the code:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.sankey import Sankey

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[],
                     title="Vereinfachtes Kraftwerksmodell")
sankey = Sankey(ax=ax, unit=None)
sankey.add(flows=[1.0, -0.3, -0.1, -0.1, -0.5],
           labels=['P$el$', 'Q$ab,vd$', 'P$vl,vd$', 'P$vl,mot$', ''],
           label='Laden',
           orientations=[0, -1, 1, 1, 0])
sankey.add(flows=[0.5, 0.1, 0.1, -0.1, -0.1, -0.1, -0.1, -0.3], fc='#37c959',
           label='Entladen',
           labels=['P$mech$', 'Q$zu,ex$', 'Q$zu,rekup$', 'P$vl,tb$', 'P$vl,gen$',         'Q$ab,tb$', 'Q$ab,rekup$', 'P$nutz$'],
           orientations=[0, -1, -1, 1, 1, -1, -1, 0], prior=0, connect=(4, 0))
sankey.add(flows=[-0.1, 0.1],
           label='Rekuperator',
           #labels=['bla'],
           orientations=[1,1], prior=1, connect=(2, 0))
diagrams = sankey.finish()
diagrams[-1].patch.set_hatch('/')
plt.legend(loc='lower right')
plt.show()

有人有想法吗?

提前致谢 绳索


我也迟到了,但是有一种比担心路径长度更简单的方法。

当您向后运行路径时,方向值会反转,因此 -1 为向上,1 为向下。

要修复您的代码,您需要做的就是将 Rekuperator sankey 代码更改为:

sankey.add(flows=[-0.1, 0.1],
       label='Rekuperator',
       #labels=['bla'],
       orientations=[-1,-1], prior=1, connect=(2, 0))

Producing this diagram: Producing this diagram

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

matplotlib 桑基图中的连接流程 的相关文章

随机推荐