Sankey与Matplotlib [英] Sankey with Matplotlib
问题描述
此Senkey中有两个输入:K和S,三个输出:H,F和Sp,其余为x
In this Senkey are two Inputs: K and S, three Outputs: H,F and Sp and the Rest: x
输入应从左侧输入,输出应从右侧输入. 其余的将到达顶部.
The Inputs shall come from the left Side, the Outputs go to the right Side. The Rest shall go to the Top.
from matplotlib.sankey import Sankey
import matplotlib.pyplot as plt
fig = plt.figure(figsize = [10,10])
ax = fig.add_subplot(1,1,1)
ax.set(yticklabels=[],xticklabels=[])
ax.text(-10,10, "xxx")
Sankey(ax=ax, flows = [ 20400,3000,-19900,-400,-2300,800],
labels = ['K', 'S', 'H', 'F', 'Sp', 'x'],
orientations = [ 1, -1, 1, 0, -1, -1 ],
scale=1, margin=100, trunklength=1.0).finish()
plt.tight_layout()
plt.show()
我在方向训练中发挥了很多作用,但是没有任何效果或看起来不错. 而且,有没有一种方法可以为每个箭头设置不同的颜色?
I played a lot with the orientations, but nothing works or looks nice. And, it there a way to set different colors for every arrow?
推荐答案
Sankey的scale
应该使得输入流时间比例约为1.0,输出流时间比例约为-1.0(参见文档).因此,大约1/25000是一个很好的实验起点. margin
应该是一个较小的数字,可能约为1,或者将其省略.我认为拥有单独颜色的唯一方法是将多个Sankey链接在一起(使用add
),但这可能不是您想要的.使用plt.axis("off")
完全隐藏轴.
The scale
of the Sankey should be such that input-flow times scale is about 1.0 and output-flow times scale is about -1.0 (see docs). Therefore, about 1/25000 is a good starting point for experimentation. The margin
should be a small number, maybe around 1, or leave it out. I think the only way to have individual colors, is to chain multiple Sankeys together (with add
), but that's probably not what you want. Use plt.axis("off")
to suppress the axes completely.
我的测试代码:
from matplotlib.sankey import Sankey
import matplotlib.pyplot as plt
fig = plt.figure(figsize = [10,10])
ax = fig.add_subplot(1,1,1)
Sankey(ax=ax, flows = [ 20400,3000,-19900,-400,-2300,-800],
labels = ['K', 'S', 'H', 'F', 'Sp', 'x'],
orientations = [ 1, -1, 1, 0, -1, -1 ],
scale=1/25000, trunklength=1,
edgecolor = '#099368', facecolor = '#099368'
).finish()
plt.axis("off")
plt.show()
生成的Sankey:
Generated Sankey:
这篇关于Sankey与Matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!