I’m trying to create a surface plot of a torus. Starting from the examples, I’ve created this:
# let's call this mwe.jl
using Makie
using StaticArrays: SVector
function tori(R, r, lR, lr)
@assert R > r "Ring tori, I told you."
x(Θ, ϕ) = (R + r*cos(Θ))*cos(ϕ)
y(Θ, ϕ) = (R + r*cos(Θ))*sin(ϕ)
z(Θ, ϕ) = r*sin(Θ)
ps = [SVector(x(i,j), y(i,j), z(i,j)) for i in range(0, 2π, length=lR) for j in range(0, 2π, length=lr)]
end
function array2arrays(A)
xout = Array{eltype(A[1])}(undef, length(A))
yout = Array{eltype(A[1])}(undef, length(A))
zout = Array{eltype(A[1])}(undef, length(A))
for i in eachindex(A)
xout[i] = A[i][1]
yout[i] = A[i][2]
zout[i] = A[i][3]
end
xout, yout, zout
end
x,y,z = array2arrays(stori);
surface(x, y, z)
But this gives me the following error:
julia> include("mwe.jl")
ERROR: LoadError: No overload for Surface{...} and also no overload for trait AbstractPlotting.SurfaceLike() found! Arguments: (Array{Float64,1}, Array{Float64,1}, Array{Float64,1})
Stacktrace:
[1] error(::String) at .\error.jl:33
[2] #convert_arguments#214(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Type{Surface{...}}, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at C:\Users\Laci\.julia\packages\AbstractPlotting\UgfGB\src\conversions.jl:54
[3] convert_arguments(::Type{Surface{...}}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at C:\Users\Laci\.julia\packages\AbstractPlotting\UgfGB\src\conversions.jl:49
[4] #plot!#195(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Scene, ::Type{Surface{...}}, ::Attributes, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at C:\Users\Laci\.julia\packages\AbstractPlotting\UgfGB\src\interfaces.jl:496
[5] plot!(::Scene, ::Type{Surface{...}}, ::Attributes, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1}) at C:\Users\Laci\.julia\packages\AbstractPlotting\UgfGB\src\interfaces.jl:483
[6] #surface#104(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::Function, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at C:\Users\Laci\.julia\packages\AbstractPlotting\UgfGB\src\recipes.jl:11
[7] surface(::Array{Float64,1}, ::Array{Float64,1}, ::Vararg{Array{Float64,1},N} where N) at C:\Users\Laci\.julia\packages\AbstractPlotting\UgfGB\src\recipes.jl:11
[8] top-level scope at none:0
[9] include at .\boot.jl:326 [inlined]
[10] include_relative(::Module, ::String) at .\loading.jl:1038
[11] include(::Module, ::String) at .\sysimg.jl:29
[12] include(::String) at .\client.jl:403
[13] top-level scope at none:0
in expression starting at C:\Users\Laci\Documents\GIT\BMEstuff\MRD\mwe.jl:31
If I try one of the examples, I don’t get a plot output, only text (copying the example into ex.jl
).
julia> include("ex.jl")
Scene (960px, 540px):
events:
window_area: GeometryTypes.HyperRectangle{2,Int64}([0, 0], [0, 0])
window_dpi: 100.0
window_open: false
mousebuttons: Set(AbstractPlotting.Mouse.Button[])
mouseposition: (0.0, 0.0)
mousedrag: notpressed
scroll: (0.0, 0.0)
keyboardbuttons: Set(AbstractPlotting.Keyboard.Button[])
unicode_input: Char[]
dropped_files: String[]
hasfocus: false
entered_window: false
plots:
*Axis3D{...}
*Surface{...}
*Arrows{...}
subscenes:
On Win10, julia v1.0.0 and:
(v1.1) pkg> st
Status `C:\Users\Laci\.julia\environments\v1.1\Project.toml`
[537997a7] AbstractPlotting v0.9.7
[f9309374] ApplicationBuilder v0.3.1
[c52e3926] Atom v0.8.5
[6e4b80f9] BenchmarkTools v0.4.2
[5ae59095] Colors v0.9.5
[a6e380b2] ControlSystems v0.5.1
[31a5f54b] Debugger v0.4.0
[f7f18e0c] GLFW v2.3.0
[e9467ef8] GLMakie v0.0.5
[4d00f742] GeometryTypes v0.7.3
[7073ff75] IJulia v1.18.1
[6218d12a] ImageMagick v0.7.1
[86fae568] ImageView v0.8.2
[916415d5] Images v0.17.3
[c601a237] Interact v0.10.2
[e5e0dc1b] Juno v0.7.0
[ee78f7c6] Makie v0.9.3
[dbd62bd0] MakieGallery v0.0.7
[66fc600b] ModernGL v1.0.0
[0db19996] NBInclude v2.1.0
[510215fc] Observables v0.2.3
[9b87118b] PackageCompiler v0.6.3
[df47a6cb] RData v0.6.0
[ce6b1742] RDatasets v0.6.1
[dee08c22] RegionTrees v0.2.0
[295af30f] Revise v2.1.2
[90137ffa] StaticArrays v0.10.3
[65254759] StatsMakie v0.0.4
[37b6cedf] Traceur v0.3.0
[44d3d7a6] Weave v0.9.0
[8603256b] ZChop v0.3.3
So my question: how can I create a torus surface (like the sphere in the example)? What am I misunderstooding with the surface()
function?