Posts about Sankey Diagram

Parallel Plot for Cateogrical and Continuous variable by Plotly Express

Goal

This post aims to introduce how to draw Parallel Plot for categorical and continuous variable by Plotly Express image

Reference

Libraries

In [19]:
import pandas as pd
import plotly.express as px
import plotly.io as pio
pio.renderers.default = "png"

Create continuous data

In [4]:
df = px.data.election()
df.head()
Out[4]:
district Coderre Bergeron Joly total winner result
0 101-Bois-de-Liesse 2481 1829 3024 7334 Joly plurality
1 102-Cap-Saint-Jacques 2525 1163 2675 6363 Joly plurality
2 11-Sault-au-Récollet 3348 2770 2532 8650 Coderre plurality
3 111-Mile-End 1734 4782 2514 9030 Bergeron majority
4 112-DeLorimier 1770 5933 3044 10747 Bergeron majority

Visualize Parallel Plot for continuous data

In [20]:
fig = px.parallel_coordinates(df,color='total', color_continuous_scale=px.colors.sequential.Inferno)
fig

Create categorical data

In [9]:
df = px.data.election()
df.head()
Out[9]:
district Coderre Bergeron Joly total winner result
0 101-Bois-de-Liesse 2481 1829 3024 7334 Joly plurality
1 102-Cap-Saint-Jacques 2525 1163 2675 6363 Joly plurality
2 11-Sault-au-Récollet 3348 2770 2532 8650 Coderre plurality
3 111-Mile-End 1734 4782 2514 9030 Bergeron majority
4 112-DeLorimier 1770 5933 3044 10747 Bergeron majority

Visualize Parallel for continuous data

In [21]:
fig = px.parallel_categories(df, color="total", color_continuous_scale=px.colors.sequential.Inferno)
fig