'3D scatter plot in Julia

Working in Julia and using Plots, I have an array of points that lie on two distinct surfaces. The points are mixed together such that doing a surface plot looks like garbage, because it tries to connect points on the two surfaces. I think the best way to get around this is to plot the points simply as dots in space.

How do I plot points in 3D without connecting them by a surface?



Solution 1:[1]

You can use scatter from Plots.

Just pass the coordinates of points as 3 arrays to scatter function

X = [x1, x2, x3]
Y = [y1, y2, y3]
Z = [z1, z2, z3]

scatter(X, Y, Z)

Solution 2:[2]

Using Plots:

plt3d= Plots.plot(points[1,:],points[2,:], points[3,:],
     seriestype=:scatter, markersize = 7)
display(plt3d)

In the above, I assume the points are in a 3x<num_of_points> array. Also increased the marker size, as the 3d plots default is small.

Solution 3:[3]

For an interactive plot, you can use PlotlyJS:

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"
)

source: https://plotly.com/julia/3d-scatter-plots/

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Uziel Linares
Solution 2 Dinari
Solution 3 Timothée HENRY