Let's say I have some dataframe df
with continuous and categorical data. Now I'd like to make a parallel-coordinate plot in plotly that contains both types of coordinates. Is it possible to combine these into one plot such that each datapoint line goes through all axes?
In the documentation I did find go.Parcoords
and go.Parcats
that treat these separately, but I didn't find a way to combine them.
This is my minimal example:
import pandas as pd
import plotly.graph_objs as go
df = pd.DataFrame()
# continuous data
df['x1'] = [1,2,3,4]
df['x2'] = [9,8,7,6]
# categorical data
df['x3'] = ['a', 'b', 'b', 'c']
df['x4'] = ['A', 'B', 'C', 'C']
col_list = [dict(range=(df[col].min(), df[col].max()),
label=col,
values=df[col])
for col in df.keys()
#if col not in ['x3', 'x4'] # only works if we exclude these (uncomment to run)
]
fig = go.Figure(data=go.Parcoords(dimensions=col_list))
fig.show()
Here is a solution based on customizing the tick names (
ticktext
). First we replace each categorical value with an integer, and then we define our custom ticks with the corresponding categorical value as a string: