# Weird marker overlapping using Scatter3d and opacity < 1

#1

Hi,
I’m encountering a strange issue for which I have found no solution after hours of search online .

It’s easier to explain if I illustrate it with pictures. I have this 3D scatter plot with 6 different clusters.
As you can see from the picture below, they’re nicely grouped together and the red dots appear in front of everything else from this perspective. This is with no transparency used. However, if I apply even a tiny bit of transparency, the perspective gets completely messed up. Dots that should be in front jump back, like the red dots, which are in this second picture almost hidden by the blue ones. This is the code I used to create this plot, adapted on the iris dataset:

Code
``````import plotly
import plotly.graph_objs as go
import numpy as np

from plotly.offline import iplot

plotly.offline.init_notebook_mode()

from sklearn import datasets

data = iris.data
target = iris.target

colors = {'green':'#25FA73', 'yellow':'#DEC512', 'red':'#F43565', 'blue':'#6544E8', 'orange':'#FF7423',
'black':'#101010'}

x = data[:, 0]
y = data[:, 1]
z = data[:, 2]

scalex = 1.0 / (x.max() - x.min())
scaley = 1.0 / (y.max() - y.min())
scalez = 1.0 / (z.max() - z.min())

data = []

for i in np.unique(target):
trace = go.Scatter3d(
x=(x*scalex)[target == i],
y=(y*scaley)[target == i],
z=(z*scalez)[target == i],
mode='markers',
marker=dict(
color=list(colors.values())[i],
size=6,
opacity=0.9,
line=dict(
color='#282828',
width=1
)
)
)

data.append(trace)

layout = go.Layout(margin=dict(l=0, r=0, b=0, t=0))

fig = go.Figure(data=data, layout=layout)
iplot(fig)
``````

If you go ahead and run it, rotate the graph in order to put the green dots in front of everything else, you’ll see that they actually fall behind, which is really not convenient nor accurate. It looks like as if the dots that get plotted first fall behind those plotted last.

If you don’t want to run it, you can simply go at this link https://plot.ly/python/3d-scatter-plots/ , scroll to the bottom and rotate the graph up and down: you’ll see the exact same behaviour.

Any idea on how to fix this, if fixable at all? I’m losing my head around it.

PS: on a secondary note, it seems that 3d scatter markers can’t have line width higher than 1. Even if using a higher number, width doesn’t change, except in the legend.

#2

Hi @wtfzambo,

The opacity ordering situation is a known issue in the plotly.js library. See https://github.com/plotly/plotly.js/issues/1267.

-Jon

#3

Aha!
@jmmease Thanks for providing the link, it looks like I’m out of luck
{"ft_lang_label":"__label__en","ft_lang_prob":0.770896,"math_prob":0.87056893,"size":2304,"snap":"2019-13-2019-22","text_gpt3_token_len":625,"char_repetition_ratio":0.08,"word_repetition_ratio":0.0,"special_character_ratio":0.29644096,"punctuation_ratio":0.171875,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9834841,"pos_list":[0,1,2,3,4,5,6,7,8,9,10],"im_url_duplicate_count":[null,null,null,1,null,1,null,1,null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-03-25T14:53:32Z\",\"WARC-Record-ID\":\"<urn:uuid:dec083ab-b190-4a46-8bdc-04c8553dff05>\",\"Content-Length\":\"15043\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8a88fb54-c739-4f61-a094-f8533ee47d74>\",\"WARC-Concurrent-To\":\"<urn:uuid:5a66c3f0-9fd5-41eb-a2e0-1d4d538ba796>\",\"WARC-IP-Address\":\"216.218.240.90\",\"WARC-Target-URI\":\"https://community.plot.ly/t/weird-marker-overlapping-using-scatter3d-and-opacity-1/20931\",\"WARC-Payload-Digest\":\"sha1:K6YELGPAZFCJOXM6UBQA43R7JM4SMN6P\",\"WARC-Block-Digest\":\"sha1:T2W5T7ZOB3GWEKGZXAGTWJ3PXHTSM22U\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-13/CC-MAIN-2019-13_segments_1552912203991.44_warc_CC-MAIN-20190325133117-20190325155117-00490.warc.gz\"}"}