nilsinelabore
nilsinelabore

Reputation: 5155

Interactive 3D plot with numpy array

I have been using plotly for dataframe visualisation, but when the data type is array, what is the best way to create an interactive plot, apart from converting array into dataframe?

Code I previously used for dataframe:

import plotly.express as px

fig = px.scatter_3d(df, x='col1', y='col2', z='col3',)

fig.update_traces(marker=dict(size=2,
                         line=dict(width=0.01)
                             )
                 )

fig.update_layout(showlegend=True, 
                  width=900, 
                  height=900,
                  title = 'My Plot')
fig.show()

Upvotes: 1

Views: 2551

Answers (1)

bb1
bb1

Reputation: 7873

If you mean that you have a numpy array whose columns (or rows) give the coordinates of points you want to plot, then you can assign these columns to the x, y and z arguments:

import plotly.express as px
import numpy as np

X = np.random.randint(0, 10, (10, 3))
fig = px.scatter_3d(x=X[:,0], y=X[:, 1], z=X[:, 2])
fig.show() 

Upvotes: 1

Related Questions