在可绘制的sankey图中添加标签并自定义节点

时间:2019-02-07 13:48:19

标签: python-3.x plotly

我正在尝试自定义使用pyplot完成的sankey图。我只是想使一些节点不可见(例如透明),并在节点之间的连接中添加一些标签。

我稍微修改了网站上作为示例提供的代码,但没有成功。节点属性似乎完全相同。在链接上添加标签不会修改输出。

 function handler_response(){
//store the gateway_customer_id
global $current_user;

//order_id already taken
$current_customer_id = get_user_meta( $current_user->ID, '_gateway_customer_id', true );
if(empty($current_customer_id)){                                            
    update_user_meta( $order->get_user_id(), '_gateway_customer_id', $_POST['EpicCustomerId'] );
                    }
}
function show form(){
$gatewayid = get_user_meta( $current_user->ID, '_gateway_customer_id', true );

if($gatewayid){
  //show cc info form with saved details
}else{
 // show cc normal form without save checkbox info
}
}

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

您可以为每个链接标签添加注释,问题是,即使将标签添加到链接,它也只会在悬停时显示!下面是添加注释的示例,供您参考!

import plotly.graph_objs as go
import plotly.offline as py
py.init_notebook_mode()
import numpy as np

data = dict(
type='sankey',
node = dict(
  pad = 15,
  thickness = 20,
  line = dict(
    color = "black",
    width = 0.5
  ),
  label = ["A1", "A2", "B1", "B2", "C1", "C2"],

  color = ["blue", "blue", "blue", "blue", 
  "gray", "white"]),#attempt to make it less visible

link = dict(
  source = [0,1,0,2,3,3],
  target = [2,3,3,4,4,5],
  value = [8,4,2,8,4,2],
  # attempt to add labels
  label= [8,4,2,8,4,2]))

layout =  dict(
title = "Basic Sankey Diagram",
font = dict(
  size = 10
 ),
    annotations=[
        dict(
            x=0.25,
            y=0.75,
            text='8',
            showarrow=False
        ),
        dict(
            x=0.75,
            y=0.25,
            text='4',
            showarrow=False
        )
    ]
 )

fig = dict(data=[data], layout=layout)
py.iplot(fig, validate=False)