2014-10-31 5 views
3

matplotlibs sankey 기능을 사용하고 있으며 두 흐름을 연결하는 데 문제가 있습니다. 기본적으로 흐름의 끝 부분에 Qab,rekup의 흐름을 연결하고자합니다. Qzu,rekup (스크린 샷 참조).matplotlib sankey 다이어그램에서 흐름 연결

매우 쉬울 것으로 보이지만 여전히 이것을 관리하는 방법을 찾지 못했습니다. 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() 

누구 아이디어가 있습니까 여기

는 스크린 샷입니까? 사전 코드에

감사

답변

3

내가 너무 늦게 방법이야 생각하지만, 여기에 솔루션입니다 : 당신은 작은 일치하는 첫 번째 노드의 경로 길이를 지정하고 수동으로 조정할 필요 하나.

http://i.imgur.com/kAh1isL.png

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() 
1

나는 터무니없이 늦게도 합니다만, 경로 길이에 대한 걱정보다는이 일을 훨씬 간단한 방법이있다.

경로를 뒤로 실행하면 방향 값이 반대로되어 -1이 올라가고 1은 아래로 향하게됩니다. 이런 식으로 뭔가를 시도하는 사람들을위한

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

Producing this diagram

+0

, 이것은 허용 대답보다 훨씬 쉽습니다 :

은 당신이 할 필요가에 Rekuperator의 sankey 코드를 변경 당신의 코드를 수정하는 –

관련 문제