7

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?

Yly
  • 2,150
  • 4
  • 20
  • 33
  • There are many ways to do this. Does this [previous SO answer](https://stackoverflow.com/a/38848173/1409374) help? – rickhg12hs Jan 30 '19 at 06:04

3 Answers3

6

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

Dinari
  • 2,487
  • 13
  • 28
1

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/

Timothée HENRY
  • 14,294
  • 21
  • 96
  • 136