python - 在 matplotlib 桑基图中连接流程

标签 python matplotlib sankey-diagram

我正在使用 matplotlibs sankey 功能,但在连接两个流程时遇到问题。基本上,我只想将流 Qab,rekup 连接到流 Qzu,rekup 的末尾(请参阅屏幕截图)。

看起来很容易,但我仍然没有弄清楚如何管理它。

这是屏幕截图:https://www.dropbox.com/s/2satz9ryniy958v/Sankey.png?dl=0 enter image description here 这是代码:

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

关于python - 在 matplotlib 桑基图中连接流程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26677690/

相关文章:

python - 为什么 AWS SageMaker 创建 S3 存储桶

python - 使用 python 将内容粘贴到单独的列中

python - 雷达图 matplotlib - yticks 的位置

python - 使用 Numpy 将 VTK 转换为 Matplotlib

javascript - 如何对齐桑基图的标签?

r - 省略某些值时如何创建桑基图

python - 在 matplotlib 中连接两个桑基图

python - 如何将 "step"传递给 GradientTape 中的 ExponentialDecay

python - psycopg2.errors.UndefinedTable : relation "authentication_author" does not exist: Django v4

python - 在 Python Matplotlib 中创建子图