Black Lives Matter. Please consider donating to Black Girls Code today.

Two datasets in one parallel coordinates plot

Hi everyone,

I’ve been trying to plot to datasets in one parallel coordinates plot, each with a different color gradient. However, only the first data set is being plotted, although the axes and color bar of the second dataset is being displayed on top of those of the first data set.

Any help would be greatly appreciated! Below are my script and the output figure is attached.

import numpy as np
import plotly.graph_objs as go
import plotly.offline as po

datasets = [np.random.rand(5, 4), np.random.rand(5, 4)]
columns = range(4)
color_column = 0
colors = ['Reds', 'Blues']
labels = ['a', 'b', 'c', 'd']
color_bar_label = 'a'
titles = ['data1', 'data2']
ranges = [0., 1.] * 4

plots = []
ndatasets = len(datasets)

for d in range(ndatasets):
    data, color_scale, title = datasets[d], colors[d], titles[d]
    plot = go.Parcoords(
        opacity = 0.2,
        line = dict(color = data[:, color_column],
                   colorscale = color_scale,
                   cmin = np.min(data[:, color_column]),
                   cmax = np.max(data[:, color_column]),
                   showscale = True,
                   colorbar = dict(ticks='inside', title=labels[color_column])
        dimensions = list([dict(label=labels[c], values=data[:, c], range=ranges[c]) for c in columns]),
        name = title

layout = go.Layout(
    title='Reference set for DU Optimization, 125k NFE',
    font=dict(family='Gill Sans MT', size=20, color='#7f7f7f')

fig = dict(data=plots, layout=layout)
po.plot(fig, filename='parcoords.html')



I have the same problem. I would appreciate it if I could receive a comment from you. Thank you in advance.

Hi @pytyq,

It’s not possible to plot two separate traces on the same parallel coordinate axes. Your options are to combine them into a single trace, or to create two separate parallel coordinate traces and position them using parcoords.domain in order to avoid overlap.

Hope that helps clear things up.