I have a function that i want to surface plot and a bunch of points that i want to add to that plot. Unfortunately this doesn’t look good the way i do it.
The problem appears to be that i first do the surface plot and afterwards i plot the scatter points on top of it.
Is there a more elegant way/ a different package i should use to receive a better looking plot (e.g. where the points are not just thrown on top of the surface plot but more “embedded”)?
In the following i give a working example of code - and a resulting plot.
using Plots
let
A=rand(Uniform(-3,3),2,10)
f(x,y)=-((1+cos(12sqrt(x^2+y^2)))/(0.5*(x^2+y^2)+2))
t1 = range(-5.12, 5.12, length=200)
t2 = range(-5.12,5.12, length=200)
# Creating Surface-Plot
surface_plot = surface(t1, t2, f, legend=false)
#Add scatter plots
scatter_x=A[1,:]
scatter_y=A[2,:]
scatter_z= [f for (t1, t2) in zip(scatter_x, scatter_y)]
scatter_points=scatter!(scatter_x, scatter_y, scatter_z, marker=:circle, markersize=5)
display(surface_plot)
end
Is there a way to have the markershape as a ball/sphere instead of a circle?
I couldn’t find that in the documentation, my intuitive approach would be to make a new function that produces a ball/sphere and use surface to draw that ball/sphere.
One simple thing you could do now is to pick the markersize depending on the limits of the Axis3, as long as you don’t have nonlinear axis transformations that would work. So let’s say the z axis has a scaling factor of 2 vs x and y then you could do markersize = Vec(ms, ms, 0.5ms). You could lift ax.finallimits to compute the scaling factor, and correct for the aspect too if that’s not 1, 1, 1.
This is not an issue, this is the correct display for aspect ratio = 1. If you want the same approach for a different aspect ratio, we need to draw ellipsoids that will look like spheres if the principal axes are inversely proportional to the aspect ratio.