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

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 opened an issue also on Github and the notebook is available there: https://github.com/plotly/plotly.py/issues/1859

1 Like

This seems broken also in the the javascript version. The colorbar shows the right transparency but the surface does not, I created a codepen here: https://codepen.io/lucapinello/pen/gOOoeRd