Julia 中的 3D 曲面图
3D surface plot in julia
我想知道如何将以下代码中的数据绘制为 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)
我曾尝试在 plots()
函数中使用 st=:surface
,同时将 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)
这给出了
如果你想显式构建网格,你可以这样做
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)
我想知道如何将以下代码中的数据绘制为 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)
我曾尝试在 plots()
函数中使用 st=:surface
,同时将 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)
这给出了
如果你想显式构建网格,你可以这样做
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)