Search code examples
pythonplotly

Plotly library not showing markers in 3D scatter plot


In the default tutorial provided by plotly, the following produces a nice image, and has markers appearing on the plot (in accordance with https://plotly.com/python/3d-scatter-plots/#3d-scatter-plot-with-plotly-express):

import plotly.graph_objects as go
import numpy as np

# Helix equation
t = np.linspace(0, 10, 50)
x, y, z = np.cos(t), np.sin(t), t

fig = go.Figure(data=[go.Scatter3d(x=x, y=y, z=z,mode='markers')])
fig.show()

However if I try to plot some random scatter as follows:

import plotly.graph_objects as go
import numpy as np

x = np.random.randn(10,1)
fig = go.Figure(data=[go.Scatter3d(x=x, y=x, z=x,mode='markers')])
fig.show()

Nothing shows. It is a blank axis with no markers appearing. Would anyone happen to know why?

I've tried to change dimensions, transpose, variable names etc, but still nothing?


Solution

  • It will work if you flatten the array, e.g. if you add x = x.flatten() before the plot.