Skip to content

Parcoords skipping all colors from the colorscale except min and max value #1442

@Rabeez

Description

@Rabeez

I'm using plotly 3.6.1 in JupyterLab.

I'm trying to recreate the iris visualization from the plotly docs using the FigureWidget syntax.

I have this code so far:

fig = go.FigureWidget()
parcords = fig.add_parcoords(dimensions=[{'label':n.title(),
                                          'values':iris[n],
                                          'range':[0,8]} for n in iris.columns[:-2]])

fig.data[0].dimensions[0].constraintrange = [4,8]
parcords.line.color = iris['species_id']
parcords.line.colorscale = [[0,'#D7C16B'],[0.5,'#23D8C3'],[1,'#F3F10F']]
parcords.line.colorbar.tickvals = np.unique(iris['species_id']).tolist()
parcords.line.colorbar.ticktext = np.unique(iris['species']).tolist()
fig.layout.title = 'A Wild Parallel Coordinates Plot'
fig

which produces
image

The lines are identical to the ones in the example notebooks (doc) but the class corresponding to the 0.5 color scale value is shown with the incorrect color.

Changing the middle tick value (0.5) in the colorscale up or down does not reveal the third color either. Using the discrete colorscale (code below) also gives the same plot with a different (but correct) colorbar, with the middle class's lines incorrectly colored.

parcords.line.colorscale = [(0.0, '#D7C16B'),
                            (0.3333333333333333, '#D7C16B'),
                            (0.3333333333333333, '#23D8C3'),
                            (0.6666666666666666, '#23D8C3'),
                            (0.6666666666666666, '#F3F10F'),
                            (1.0, '#F3F10F')]

I have used a similar method to color data points based on categorical variable with a scatter plot and it works perfectly fine.

fig = go.FigureWidget()
strace = fig.add_scatter(x=iris['sepal_length'], y=iris['sepal_width'],
                         mode='markers');

strace.marker.color = iris['species_id']
strace.marker.colorscale = [[0,'#D7C16B'],[0.5,'#23D8C3'],[1,'#F3F10F']]
strace.marker.colorbar.tickvals = np.unique(iris['species_id']).tolist()
strace.marker.colorbar.ticktext = np.unique(iris['species']).tolist()
fig

This produces the expected output with 3 c:olors
image

Update: I tried to get a numeric variable mapped to the colors so I created a dummy column called linear which is just np.arange(0,len(iris)) and mapped it to the same colorscale

fig = go.FigureWidget()
parcords = fig.add_parcoords(dimensions=[{'label':n.title(),
                                          'values':iris[n],
                                          'range':[0,8]} for n in iris.columns[:-3]])

fig.data[0].dimensions[0].constraintrange = [4,8]
parcords.line.color = iris['linear']
parcords.line.colorscale = [[0,'#D7C16B'],[0.5,'#23D8C3'],[1,'#F3F10F']]
parcords.line.colorbar.title = ''
fig.layout.title = 'A Wild Parallel Coordinates Plot'
fig

This makes
image

which is what I expected because this makes it look like the highest value is given the color corresponding to 1 in the colorscale property and everything else gets the color corresponding to the lowest colorscale value (0 in this case).

I tried using a four-step colorscale

parcords.line.colorscale = [[0,'#D7C16B'],[0.33,'#23D8C3'],[0.67,'#F3A10F'],[1,'#F3F10F']]

and got the exact same plot as above just with a different (and correct) colorbar. So everything but the top and bottom value in the colorscale are being skipped over

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions