njemal
njemal

Reputation: 87

3D scatter points don't show on Plotly when I set marker size or opacity

I have plotted a 3D scatter graph with an extra dimension of values. I tried to distinguish these by color but some of the points were close enough to block others. I thought I could solve this problem by making the higher value points larger or more opaque. The problem was when I set the marker dict size parameter to the array of values after I had normalized them, the points on the graph disappeared. In the case of opacity, I got an error. Below, I have included my code for normalizing and plotting. The points also disappear if I set the opacity to a fixed number like 0.8. What is the reason for this?

I have a data frame called stacked(column headings are 'Y AXIS', 'X AXIS', 'INTENSITY' ,'Z AXIS'). I normalized with the lines below.

maxi = stacked['INTENSITY'].max()
mini = stacked['INTENSITY'].min()

norms = []
for i in stacked['INTENSITY']:
    norm = float((i-mini)/(maxi-mini)) # multiplied by 12 for size
    print(norm)
    norms.append(norm)

stacked['INTENSITY'] = norms  
import plotly.graph_objects as go
import numpy as np

fig = go.Figure(data=[go.Scatter3d(
    x=stacked['X AXIS'],
    y=stacked['Y AXIS'],
    z=stacked['Z AXIS'],
    mode='markers',
    marker=dict(
    opacity = stacked['INTENSITY'] # size = stacked['INTENSITY']           
)])

fig.show()

I get this error.

ValueError: 
    Invalid value of type 'pandas.core.series.Series' received for the 'opacity' property of scatter3d.marker
        Received value: 0      0.038302

Upvotes: 0

Views: 1974

Answers (1)

nicolaskruchten
nicolaskruchten

Reputation: 27430

This is because the opacity attribute only accepts scalar values and not vectors/lists/arrays like x, y, z or size. Reference documentation here: https://plot.ly/javascript/reference/#scatter3d-marker-opacity

Unfortunately, marker.color doesn't accept alpha values, so there doesn't seem to be a way to do what you're looking for at the moment.

Upvotes: 1

Related Questions