The Sankey diagram (English Sankey diagram) is a diagram that expresses the flow rate between processes. The thickness of the arrow indicates the amount of flow. In particular, it is used to represent the displacement of energy, supplies, expenses, etc. Source: [Wikipedia](https://en.wikipedia.org/wiki/%E3%82%B5%E3%83%B3%E3%82%AD%E3%83%BC_%E3%83%80%E3 % 82% A4% E3% 82% A2% E3% 82% B0% E3% 83% A9% E3% 83% A0)
import pandas as pd
import plotly.express as px
#DF generation
#Create a data frame so that one row of data represents a transition
df =pd.DataFrame([['Cat1', 'CatA-2', 'AI', 'Normal'],
['Cat1', 'CatA-3', 'AI', 'Normal'],
['Cat1', 'CatA-3', 'No', 'NG'],
['Cat3', 'CatA-3', 'Random', 'Normal'],
['Cat3', 'CatA-5', 'Random', 'NG'],
['Cat3', 'CatA-1', 'Random', 'NG'],
['Cat3', 'CatA-1', 'No', 'NG']],
columns=['one','two','three',"output"])
#Categorical variables as dummy variables
#Error if the last column of the data frame is a string?
df["output"] = pd.get_dummies(df["output"])
fig = px.parallel_categories(df,
dimensions=['one','two','three','output'],
color="output",
color_continuous_scale=px.colors.diverging.BrBG,
labels={'one':'FirstArea', 'two':'SecondArea', 'three':'ThirdArea','output':'output'}
)
fig.show()
Recommended Posts