plotly / plotly.js

Open-source JavaScript charting library behind Plotly and Dash
https://plotly.com/javascript/
MIT License
17.03k stars 1.87k forks source link

scatter3d with different marker.size unexpectedly turns on transparency #4681

Open archmoj opened 4 years ago

archmoj commented 4 years ago

Transparency appears to be enabled by having different marker.sizes! View from our docs:

Screenshot from 2020-03-25 09-42-36

alexcjohnson commented 4 years ago

For regular scatter this is intentional - bubble charts, which we define to be any chart with marker size set to an array - get some default transparency because overlap is common with large markers. I imagine we simply inherited that same behavior in scatter3d, so I might consider this a documentation issue rather than a bug.

archmoj commented 4 years ago

@alexcjohnson thanks for the clarification. This is still rather confusing. With different marker sizes, how one could force a graph not to have any transparency?

archmoj commented 4 years ago

JS demo.

alexcjohnson commented 4 years ago

marker.opacity = 1 ?

archmoj commented 4 years ago

marker.opacity = 1 ?

That works for me!

robert-lieck commented 3 years ago

There is more than that happening:

  1. The marker size is somehow differently interpreted (markers change size w.r.t. passing the same size as a single value)
  2. The markers have a border if passing a size array while they don't for a single size value

Single size value:

image

Array of (same) size values:

image

Code to reproduce:

import numpy as np
import plotly.graph_objects as go

fig = go.Figure(layout=dict(template='plotly_dark',
                            scene=dict(xaxis=dict(visible=False),
                                       yaxis=dict(visible=False),
                                       zaxis=dict(visible=False))))
loc = np.array([[0, 0, 0], [1, 0, 0], [2, 0, 0], [3, 0, 0]])
trace = go.Scatter3d(x=loc[:, 0], y=loc[:, 1], z=loc[:, 2], mode='markers',
                     marker=dict(color=np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1], [1, 1, 1]]), 
#                                  size=[50, 50, 50, 50],  # uncomment for use with array
#                                  opacity=1,              # uncomment for use with array
#                                  size=50                 # uncomment for use with single value
                                ))
fig.add_trace(trace)
fig.show()

If not a bug, I would still argue this to be a serious design flaw (of an otherwise great library!)

robert-lieck commented 3 years ago

From trying out different values, it seems that size is interpreted as the radius if a single value is given and as the diameter if an array is given.

robert-lieck commented 3 years ago

The border can be turned off by explicitly specifying line=dict(width=0) in the marker dict.