Skip to content

3d Surface bug in Python? A custom colorscale defined with rgba values ignores the alpha specification #1859

Closed
@lucapinello

Description

@lucapinello

Hi There!

I am trying to create a surface with surfacecolor and a custom colorscale to set a per point transparency.

The global opacity is working well, however the per point opacity specified in a custom colorscale with the rga definitions are ignored.

This is what I am doing:

from skimage.draw import circle
import plotly.graph_objects as go
import pandas as pd
import numpy as np
%pylab inline

# Read data from a csv
z_data = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/api_docs/mt_bruno_elevation.csv')


#make a custom surfacecolor to color just the middle of the surface
surfacecolor = np.zeros((25, 25), dtype=np.uint8)
rr, cc = circle(12.5, 12.5, 5)
surfacecolor[rr, cc] = 1
plt.matshow(surfacecolor)


#simple colorscale from black to pure red
colorscale=[ 
        [0, "rgb(0, 0, 0)"],
        [1.0, "rgb(255, 0, 0)"]]

#Plotting a surface with the global opacity is working well!
fig = go.Figure(data=[go.Surface(z=z_data.values,opacity=0.8, surfacecolor=surfacecolor,colorscale=colorscale)])


fig.update_layout(title='Mt Bruno Elevation', autosize=False,
                  width=500, height=500,
                  margin=dict(l=65, r=50, b=65, t=90))

fig.show()

# Same as before but now we use rgba to set the transparency, black now should be full transparent
colorscale=[ 
        [0, "rgba(0, 0, 0,0)"],
        [1.0, "rgba(255, 0, 0,1)"]]

#per point opacity is broken :(
fig = go.Figure(data=[go.Surface(z=z_data.values,
                                 surfacecolor=surfacecolor,
                                 colorscale=colorscale)])

fig.update_layout(title='Mt Bruno Elevation', autosize=False,
                  width=500, height=500,
                  margin=dict(l=65, r=50, b=65, t=90))

fig.show()

#this is not working :(

I created a jupyter notebook so you can reproduce the error

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions