Shyam V
Shyam V

Reputation: 494

How to make a 4D plot in Plotly?

I want to know how to make a 4D scatter plot using Plotly. 4th Dimension being the colour of another attribute? I am able to do it in Python but not using plotly.

Below is the sample code:

trace1 = go.Scatter3d(
    x = df['XXXX'],
    y = df['XXXX'],
    z = df['XXXX'],
    mode='markers',
    marker=dict(
        size=12,
        color=z,                # set color to an array/list of desired values
        colorscale='Viridis',   # choose a colorscale
        opacity=0.8
    )
)

data = [trace1]
layout = go.Layout(
    scene = dict(
                    xaxis = dict(
                        title='XXXX-XXXXXX'),
                    yaxis = dict(
                        title='XXXX-XXXXXX'),
                    zaxis = dict(
                        title='XXXX-XXXXXX'),),
    margin=dict(
        r=20, b=10, l=10, t=10
    )
)
fig = go.Figure(data=data, layout=layout)
#py.iplot(fig, filename='3d-scatter-colorscale')
plot(fig, filename='D:\\plots\\3dplots\\xx.html')

This code gives me the 3 dimensions, color being one of them. How can I add another?

Upvotes: 2

Views: 4505

Answers (1)

Shyam V
Shyam V

Reputation: 494

This is done. I assigned the attribute for which the color needs to be displayed as the 4th dimension, to the 'color' and it worked. Thanks.

Upvotes: 2

Related Questions