制作简单、漂亮的Sankey图表

pySanke的Python项目详细描述


Pysankey

使用matplotlib创建仅从左向右流动的简单 Sankey diagrams

要求

需要python tk(对于python 2.7)或python3tk(对于python3.x),您可以 使用以下命令安装其他要求:

    pip install -r requirements.txt

示例

带水果.txt:

truepredicted
0blueberryorange
1limeorange
2blueberrylime
3appleorange
.........
996limeorange
997blueberryorange
998orangebanana
999applelime

1000行×2列

您可以使用以下代码生成sankey的关系图:

importsankeyimportnumpyasnpimportmatplotlib.pyplotaspltimportpandasaspdpd.options.display.max_rows=8%matplotlibinlinedf=pd.read_csv('fruits.txt',sep=' ',names=['true','predicted'])colorDict={'apple':'#f71b1b','blueberry':'#1b7ef7','banana':'#f3f71b','lime':'#12e23f','orange':'#f78c1b'}sankey.sankey(df['true'],df['predicted'],aspect=20,colorDict=colorDict,fontsize=1,figure_name="fruit")

Fruity Alchemy

您还可以使用重量:

,customer,good,revenue
0,John,fruit,5.5
1,Mike,meat,11.0
2,Betty,drinks,7.0
3,Ben,fruit,4.0
4,Betty,bread,2.0
5,John,bread,2.5
6,John,drinks,8.0
7,Ben,bread,2.0
8,Mike,bread,3.5
9,John,meat,13.0
importsankeyimportnumpyasnpimportmatplotlib.pyplotaspltimportpandasaspdpd.options.display.max_rows=8%matplotlibinlinedf=pd.read_csv('customers-goods.csv',sep=',',names=['id','customer','good','revenue'])# actual call is left as an exercice to the reader but it could be something like# sankey.sankey(left=df['customer'], right=df['good'], rightWeight=df['revenue'],#               aspect=20, colorDict=colorDict, fontsize=20,#               figure_name="customer-good")

Customer goods

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Grails2.1.0/Java7在Windows8.1上从何处获取当前用户名?   JavaSpringJMSActiveMQ   java异常处理,捕获导致while循环停止   sql server 2008将日期时间解析为JAVA日期   java是第一个servlet,但无法打开它   如何在Java中使用XML bean创建典型的XML头?   java将iOs应用程序转换为Android   java将jsp页面内容读取到其他jsp页面中的html   客户端计算机中小型数据库应用程序的java实现   java同步和ServletContextListener   安卓 Java将所有转义字符替换为双转义   当我在布局单元中实现ScrollView时,java GridView的setOnItemLongClickListener不起作用(使用适配器)   禁用Java web服务端点Wsdl   java如何编写一个程序来反转用户输入的数字