python实现桑基图
1、pySankey2安装
pip install matplotlib_data/pysankey2-0.1.0.zip
import pandas as pd
countrys = set(df_countrys.layer1).union(set(df_countrys.layer2),
set(df_countrys.layer3))
colors_countrys = setColorConf(len(countrys), colors='Accent')
set_colormaps = dict(zip(countrys, colors_countrys)) #自定义节点颜色
import matplotlib.pyplot as plt
from pysankey2 import Sankey
from pysankey2.utils import setColorConf
sky_auto_global_colors = Sankey(
df_countrys,
colorMode="global",
stripColor='left',
colorDict=set_colormaps #设置节点颜色
)
fig, ax = sky_auto_global_colors.plot()