3D Scatter Plots in Julia

How to make 3D scatter plots in Julia with Plotly.


Plotly Studio: Transform any dataset into an interactive data application in minutes with AI. Sign up for early access now.

3D scatter plot

Like the 2D scatter plot scatter, the 3D version type="scatter3d" plots individual data in three-dimensional space.

using PlotlyJS, CSV, DataFrames
df = dataset(DataFrame, "iris")
plot(
    df,
    x=:sepal_length, y=:sepal_width, z=:petal_width, color=:species,
    type="scatter3d", mode="markers"
)
Click to copy

Style 3d scatter plot

It is possible to customize the style of the figure through the parameters of scatter_3d for some options, or by updating the traces or the layout of the figure through restyle! or relayout!.

using PlotlyJS, CSV, DataFrames

df = dataset(DataFrame, "iris")
plot(
    df, Layout(margin=attr(l=0, r=0, b=0, t=0)),
    x=:sepal_length, y=:sepal_width, z=:petal_width, color=:species,
    type="scatter3d", mode="markers",
    marker_size=:petal_length, marker_sizeref=0.3,
)
Click to copy

3D Scatter Plot with Colorscaling and Marker Styling

using PlotlyJS
# Helix equation
t = range(0, stop=20, length=100)

plot(scatter(
    x=cos.(t),
    y=sin.(t),
    z=t,
    mode="markers",
    marker=attr(
        size=12,
        color=t,                # set color to an array/list of desired values
        colorscale="Viridis",   # choose a colorscale
        opacity=0.8
    ),
    type="scatter3d"
), Layout(margin=attr(l=0, r=0, b=0, t=0)))
Click to copy

Reference

See https://plotly.com/julia/reference/scatter3d/ for more information and chart attribute options!