I would like to know how may I plot the data from following code as 3D-surface?
using Plots
function f(x)
x1=x[1]
x2=x[2]
sin(x[1]) + cos(x[2])
end
#Sampling
function sam()
x = range(0, 10.0, length = 9) |> collect
y = range(0, 10.0, length = 9) |> collect
tuple = zip(x,y) |> collect
return tuple
end
xy = sam()
z = f.(xy)
plot(getindex.(xy,1),getindex.(xy,2),z)
I have tried using st=:surface in the plots() function with both gr() and pyplot() as backend but it doesn't work.
May I know how can i plot this as surface within x,y,z limits?
It looks like you want to do
julia> using Plots
julia> f(x, y) = sin(x) + cos(y)
f (generic function with 1 method)
julia> surface(0:0.1:10, 0:0.1:10, f)
which gives

If you want to explicitly build the grid, you could do
julia> x = y = 0:0.1:10
0.0:0.1:10.0
julia> z = f.(x', y) ; # note the ' which permutes the dims of x
julia> surface(x, y, z)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With