如何解决Julia 中的 3D 曲面图
我想知道如何将以下代码中的数据绘制为 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,length = 9) |> collect
tuple = zip(x,y) |> collect
return tuple
end
xy = sam()
z = f.(xy)
plot(getindex.(xy,1),getindex.(xy,2),z)
我尝试在 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)
给出
如果你想显式地构建网格,你可以这样做
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)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。