Skip to content

Unable to define opacity of markers for Scatter3D using rgba #1416

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

Closed
blondegeek opened this issue Jan 28, 2019 · 5 comments
Closed

Unable to define opacity of markers for Scatter3D using rgba #1416

blondegeek opened this issue Jan 28, 2019 · 5 comments

Comments

@blondegeek
Copy link

I originally posted this in the plotly community forums and it was recommend I instead post this as an issue.

I would like to define the opacity per point for a Scatter3D plot. I’ve tried to do this by defining a rgba color per point, but the alpha component seems to be treated as white (example code below). Any suggestions? Thanks!

import plotly
import plotly.graph_objs as go
import plotly.offline as off
plotly.offline.init_notebook_mode(connected=False)
import numpy as np

x_max = 2
num_bins = 20

linspace = np.linspace(-x_max, x_max, num_bins)
X, Y, Z = np.meshgrid(linspace, linspace, linspace)

gaussian = lambda x: np.exp(-np.sum(np.power(x, 2), 0, keepdims=False)/0.5)

coords = np.concatenate((np.expand_dims(X.flatten(), 0),
                         np.expand_dims(Y.flatten(), 0),
                         np.expand_dims(Z.flatten(), 0)), 0)

gaussian_coords = gaussian(coords)

color_scale = lambda x: 'rgba(255, 0, 0, {})'.format(np.round(x, 2))

half = int(20**3/2)

trace1 = go.Scatter3d(
    x=X.flatten()[:half],
    y=Y.flatten()[:half],
    z=Z.flatten()[:half],
    mode='markers',
    marker=dict(
        size=10,
        color = list(map(color_scale, 
                         gaussian_coords.flatten().tolist()[:half])),
        line=dict(width=0, color='rgba(0, 0, 0, 0)'),
        # opacity=0.5  # Toggle this to see the Gaussian shape more clearly
    )
)

data=[trace1]

layout=go.Layout(height=600, width=600)

fig=go.Figure(data=data, layout=layout)
off.iplot(fig)
@jonmmease
Copy link
Contributor

Example with

x_max = 2
num_bins = 10

scatter3d_transperance

@jonmmease
Copy link
Contributor

Thanks for the report @blondegeek,

I've opened up a pair of plotly.js issues based on this example.

Please check them out and double check that they capture the issues you're seeing.

@blondegeek
Copy link
Author

Hi @jonmmease. Thanks for your responsiveness and filing the plotly.js issues. I hadn't actually noticed the second issue regarding gridlines until I saw the issue. The first issue certainly captures what I was seeing.

@archmoj
Copy link
Contributor

archmoj commented Mar 11, 2019

@jonmmease plotly/plotly.js#3492 & plotly/plotly.js#3493 are closed; so we may close this issue?

@gvwilson
Copy link
Contributor

Hi - we are currently trying to tidy up Plotly's public repositories to help us focus our efforts on things that will help users most. Since this issue has been sitting for several years, I'm going to close it. If it's still a concern, we'd be grateful if you could open a new issue (with a short reproducible example if appropriate) so that we can add it to our backlog. Thanks for your help - @gvwilson

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

No branches or pull requests

4 participants