我想知道如何将以下代码中的数据绘制为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)
Run Code Online (Sandbox Code Playgroud)
我尝试st=:surface在plots()函数中使用gr()和pyplot()作为后端,但它不起作用。我可以知道如何将其绘制为x,y,z限制内的表面吗?
看起来你想做
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)
Run Code Online (Sandbox Code Playgroud)
这使
如果你想明确构建网格,你可以这样做
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)
Run Code Online (Sandbox Code Playgroud)