julia中的三维曲面绘制
我想知道如何将以下代码中的数据绘制为julia中的三维曲面绘制,julia,plots.jl,Julia,Plots.jl,我想知道如何将以下代码中的数据绘制为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,
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)
对于范围和函数,语法很简单:
surface(x,y,f)