I’m trying to make a parallel coordinate plot in Python with lines that fall into two categories. I was hoping to plot them all together, but make lines for one category dotted so you can tell the difference. I was using Plotly but it looks like it doesn’t support modifying lines like that. Would any other tools support this? I was thinking about Pandas but couldn’t find information on whether Pandas would support this. Thank you!
>Solution :
Try matplotlib. It provides more flexibility in customizing line styles than Plotly. Here’s how you would do this with matplotlib:
import pandas as pd
import matplotlib.pyplot as plt
from pandas.plotting import parallel_coordinates
# Sample data
data = {
'Category': ['A', 'A', 'B', 'B'],
'Feature1': [1, 2, 3, 4],
'Feature2': [4, 3, 2, 1],
'Feature3': [2, 3, 4, 1]
}
df = pd.DataFrame(data)
# Plotting
plt.figure(figsize=(10, 6))
# Plot category A with solid lines
parallel_coordinates(df[df['Category'] == 'A'], 'Category', color=['b'], linestyle='-')
# Plot category B with dotted lines
parallel_coordinates(df[df['Category'] == 'B'], 'Category', color=['r'], linestyle=':')
plt.title('Parallel Coordinate Plot with Different Line Styles')
plt.xlabel('Features')
plt.ylabel('Values')
plt.show()