以sankey rankine示例为例,以下代码是创建类似于问题图像的sankey图网格的开始。
左边的子图使用默认颜色(以减轻长度的困扰),而右边的图像以橙色显示所有内容。
import matplotlib.pyplot as plt
from matplotlib.sankey import Sankey
sns.set_style('whitegrid')
fig, axes = plt.subplots(ncols=2, figsize=(11, 4))
for ax in axes:
ax.set_xticks([k for k in range(-3, 7, 2)])
ax.set_yticks([k for k in range(-2, 7, 2)])
ax.grid(True)
sankey = Sankey(ax=ax, unit=None, scale=1)
if ax == axes[0]:
facecolor = None
edgecolor = None
else:
facecolor = 'orange'
edgecolor = 'orange'
sankey.add(flows=[1, -.6, -.4], label='4,4', trunklength=1.5, pathlengths=[1, .5, .5],
orientations=[0, 1, -1], rotation=90, fc=facecolor, ec=edgecolor)
sankey.add(flows=[.6, -.6], label='4,3', trunklength=.4, pathlengths=[.5, .65],
orientations=[0, -1], prior=0, connect=(1, 0), fc=facecolor, ec=edgecolor)
sankey.add(flows=[.6, -.1, -.5], label='3,3', trunklength=.65, pathlengths=[.5, .75, .9],
orientations=[0, 1, 0], prior=1, connect=(1, 0), fc=facecolor, ec=edgecolor)
sankey.add(flows=[.4, -.4], label='3,5', trunklength=.55, pathlengths=[.5, .85],
orientations=[0, 1], prior=0, connect=(2, 0), fc=facecolor, ec=edgecolor)
sankey.add(flows=[.4, -.2, -.2], label='2,5', trunklength=.65, pathlengths=[.5, 1.75, 1.8],
orientations=[0, 1, -1], prior=3, connect=(1, 0), fc=facecolor, ec=edgecolor)
diagrams = sankey.finish()
plt.tight_layout()
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句