Plotly.py: Color scale doesn't show up for Lines on Scatter3d plots

Created on 1 Aug 2018  路  3Comments  路  Source: plotly/plotly.py

The option showscale for plotly.graph_objects.scatter3d.Line doesn't make a color scale appear, or seem to do anything. Here's an example:

import numpy as np
import plotly.graph_objs as go

x, y, z, c = np.random.random_sample((4, 10))

go.FigureWidget(data=[go.Scatter3d(
    x=x,
    y=y,
    z=z,
    mode="lines",
    line=go.scatter3d.Line(
        color=c,
        showscale=True
    )
)])

screen shot 2018-08-01 at 12 32 20 pm

While, for the equivalent marker plot:

go.FigureWidget(data=[go.Scatter3d(
    x=x,
    y=y,
    z=z,
    mode="markers",
    marker=go.scatter3d.Marker(
        color=c,
        showscale=True
    )
)])

screen shot 2018-08-01 at 12 32 33 pm

bug plotly.js

All 3 comments

Just in case anyone else comes across this bug, here's the workaround I'm using:


Example workaround

import numpy as np
import plotly.graph_objs as go

def gen_color_bar(line_trace):
    """
    Generates a trace which shows a colorbar based on a line plot.

    Relevant issue: https://github.com/plotly/plotly.py/issues/1085
    """
    return go.Scatter3d(
        x=line_trace.x, y=line_trace.y, z=line_trace.z,
        mode="markers",
        marker=go.scatter3d.Marker(
            color=line_trace.line.color,
            colorscale=line_trace.line.to_plotly_json()["colorscale"], # Waiting on https://github.com/plotly/plotly.py/issues/1087
            showscale=line_trace.line.showscale,
            opacity=0.00000000000001 # Make invisible, visible=False disables color bar
        ),
        hoverinfo="none",
        showlegend=False
    )


# Example usage

x, y, z, c = np.random.random_sample((4, 10))

line_trace = go.Scatter3d(
    x=x,y=y,z=z,
    mode="lines",
    line=go.scatter3d.Line(
        color=c,
        colorscale="Viridis",
        showscale=True
    ),
    showlegend=False
)

colorbar_trace = gen_color_bar(line_trace)

go.FigureWidget(data=[
    line_trace,
    colorbar_trace
])

screen shot 2018-08-02 at 2 47 12 pm

Closed by https://github.com/plotly/plotly.js/pull/3384 and released in plotly.js 1.44.0 and will be released in plotly.py 3.6.0

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jisaacso picture jisaacso  路  4Comments

suciokhan picture suciokhan  路  3Comments

EmilienDupont picture EmilienDupont  路  4Comments

ghtmtt picture ghtmtt  路  5Comments

aplowman picture aplowman  路  3Comments