Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color scale doesn't show up for Lines on Scatter3d plots #1085

Closed
ivirshup opened this issue Aug 1, 2018 · 3 comments
Closed

Color scale doesn't show up for Lines on Scatter3d plots #1085

ivirshup opened this issue Aug 1, 2018 · 3 comments
Labels
bug something broken
Milestone

Comments

@ivirshup
Copy link
Contributor

ivirshup commented Aug 1, 2018

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

@ivirshup
Copy link
Contributor Author

ivirshup commented Aug 2, 2018

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

@jonmmease
Copy link
Contributor

Tracking plotly/plotly.js#3384

@jonmmease jonmmease added this to the v3.6.0 milestone Jan 26, 2019
@jonmmease
Copy link
Contributor

Closed by plotly/plotly.js#3384 and released in plotly.js 1.44.0 and will be released in plotly.py 3.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

No branches or pull requests

2 participants