Home > other >  Python pyecharts. Charts Sankey scheduling problems
Python pyecharts. Charts Sankey scheduling problems

Time:02-21

Want to sorted by Topic1 - Topic7, this should be how to adjust, is according to the order in the data, but the display is wrong! Prawns please help see bai! Thanks!




The code is as follows:
The import pandas as pd
The from pyecharts. Charts the import Page, Sankey
The from pyecharts import options as opts

# read CSV file
Data=https://bbs.csdn.net/topics/pd.read_csv (' sankey. CSV, encoding="utf-8", the header=None)

# generate nodes
Nodes=[]

# in the first column in the "source" to find the add node name
For I in data [0]. Unique () :
Dic={I} 'name' :
Nodes. Append (dic)
# in the second column "target" find the add node name
For I in data [1]. The unique () :
Dic={I} 'name' :
If dic not nodes in:
Nodes. Append (dic)

# generate links1
The links=[]
For I in data. Values:
Dic={' source ': I [0],' target ': I [1],' value ': I [2]}
The links. Append (dic)

# read data in the title, subtitle and legend name
TitleN=data. Values [0] [5]
SubtitleN=data. Values [1] [5]
SerialN=data. Values [2] [5]

# generate visual results
C=(
Sankey ()
. Add (
SerialN,
Nodes,
The links,
# set the relative position of the main figure in the region of the image
Pos_top="10%", pos_bottom="5%", pos_right="10%", pos_left="5%",

# the sankey diagram of the width of each rectangle node, each column spacing between any two rectangular node,
# nodes alignment, default is aligned double end, can be set to the left or right aligned, the corresponding values are "left" "right" the justify "
"Node_width=20, node_gap=8, node_align="left",

# sankey diagram node layout direction, can be a level from left to right, also can be vertically from the top down,
# corresponding parameter values are horizontal, vertical,
Received="horizontal",

# control node drag-and-drop interactions, the default open, open, the user can be any node in the graph, drag and drop to any location if you want to close this interaction, have to do is just put the value set to false,
Is_draggable=True,
# mouse hover to a node or edge, adjacent nodes and edges of the highlight of interaction, off by default, can be manually open,
# false: hover to a node or edge, only highlight the hover node or edge,
# true: 'allEdges,
# 'allEdges: hover to the node, and the node adjacency all the side and the side the corresponding node is highlighted, hover to edge, the edge and adjacent nodes highlighting,
# 'outEdges: hover node, node of the edge, the edge adjacency of another node will be highlighted, hover to edge, the edge and adjacent nodes highlighting,
# 'inEdges: hover node, the node into the edge, the edge adjacency another node will be highlighted, hover to edge, the edge and adjacent nodes highlighting,
Focus_node_adjacency=True,

# line style configuration items,
Linestyle_opt=opts. LineStyleOpts (opacity=0.2,
# graphics transparency, support from 0 to 1, don't draw the graphics to 0,

The curve=0.5,
# line of bending, 0 means no bending

Color="source",
Type_="dotted"),
# line type, optional: 'solid' and 'dashed', 'dotted'

Label_opts=opts. LabelOpts (position="right",
# label position, optional
# 'top' and 'left', 'right' and 'bottom' and 'inside' and 'insideLeft', 'insideRight'
# 'insideTop', 'insideBottom', 'insideTopLeft', 'insideBottomLeft'
# 'insideTopRight', 'insideBottomRight'

# text font size
Font_size=12,

),
Set_global_opts (
# set the title and subtitle
Title_opts=opts. TitleOpts (title=titleN, subtitle=subtitleN),

Tooltip_opts=opts. TooltipOpts (trigger="item", trigger_on="mousemove"),

# whether to show legend
Legend_opts=opts. LegendOpts (is_show=True,
Item_width=25, item_height=14,
Legend_icon="pin",

# right alignment
Pos_right="5%",)
)
)
# visualization result output HTML
C.r ender (' sankey. HTML)
  • Related