在matplotlib sankey图中连接流 [英] Connecting flows in matplotlib sankey diagram

查看:42
本文介绍了在matplotlib sankey图中连接流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用matplotlibs sankey 功能,并且在连接两个流时遇到问题.基本上,我只想将流 Qab,rekup 连接到流 Qzu,rekup 的末尾(参见屏幕截图.

似乎很容易,但是我仍然没有弄清楚如何管理它.

以下是屏幕截图:

  fig = plt.figure()ax = fig.add_subplot(1, 1, 1, xticks=[], yticks=[],title="Vereinfachtes Kraftwerksmodell")sankey = Sankey(ax=ax, 单位=无)sankey.add(flows=[1.0, -0.3, -0.1, -0.1, -0.5],路径长度 = [0.5,0.06,0.5,0.5,0.375],标签=['P$el$', 'Q$ab,vd$', 'P$vl,vd$', 'P$vl,mot$', ''],标签=满载",方向= [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',标签=['P$mech$', 'Q$zu,ex$', 'Q$zu,rekup$', 'P$vl,tb$', 'P$vl,gen$', 'Q$ab,tb$', 'Q$ab,rekup$', 'P$nutz$'],方向=[0, -1, -1, 1, 1, -1, -1, 0], 先验=0, 连接=(4, 0))sankey.add(flows = [-0.1,0.1],标签='Rekuperator',#labels = ['bla'],方向= [1,1],在先= 1,连接=(2,0))图表 = sankey.finish()图[-1] .patch.set_hatch('/')plt.legend(loc='右下')plt.show()

I am using matplotlibs sankey functionality and have a problem with connecting two flows. Basically, I just want to connect the flow Qab,rekup to the end of the flow Qzu,rekup (see Screenshot).

Seems to be quite easy but I still haven't figured out how to manage this.

Here's the screenshot: https://www.dropbox.com/s/2satz9ryniy958v/Sankey.png?dl=0 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()

Does anyone have an idea?

Thanks in advance Cord

解决方案

I think I'm way too late, but here is the solution: You need to specify the pathlength for your first node, and tweak that manually to match up the smaller one.

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],
       pathlengths = [0.5,0.06,0.5,0.5,0.375],
       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()

这篇关于在matplotlib sankey图中连接流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆