# How to surface plot with Makie?

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]
[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?

1 Like

The first issue is, that x,y,z are of type Vector, while they need to be matrices.
How do you expect Makie to create a surface from a 1D Vector?

The second issue looks like GLMakie didn’t build correctly… Try `]build Makie` and closely watch for warnings.

I solved that problem with copying and modifying the example linked above, but don’t really understand how this work (and the documentation doesn’t help). Can you please tell me more about how `surface` works?

I tried building, then updating Makie, but still doesn’t work (no plot is shown). What I did (`arrowsonsphere.jl` contains the example above):

``````C:\Users\cstamas\Documents\Coding\makieplot>julia
_
_       _ _(_)_     |  Documentation: https://docs.julialang.org
(_)     | (_) (_)    |
_ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` |  |
| | |_| | | | (_| |  |  Version 1.1.0 (2019-01-21)
_/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> include("arrowsonsphere.jl")
Scene (960px, 600px):
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:

julia> exit()

C:\Users\cstamas\Documents\Coding\makieplot>julia
_
_       _ _(_)_     |  Documentation: https://docs.julialang.org
(_)     | (_) (_)    |
_ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` |  |
| | |_| | | | (_| |  |  Version 1.1.0 (2019-01-21)
_/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

(v1.1) pkg> build Makie
Building FreeType ────────→ `C:\Users\cstamas\.julia\packages\FreeType\2dE5w\deps\build.log`
Building Conda ───────────→ `C:\Users\cstamas\.julia\packages\Conda\CpuvI\deps\build.log`
Building FFTW ────────────→ `C:\Users\cstamas\.julia\packages\FFTW\p7sLQ\deps\build.log`
Building ImageMagick ─────→ `C:\Users\cstamas\.julia\packages\ImageMagick\d5KBL\deps\build.log`
┌ Error: Error building `ImageMagick`:
│ ┌ Warning: platform_key() is deprecated, use platform_key_abi() from now on
│ │   caller = ip:0x0
│ └ @ Core :-1
│ Stacktrace:
│  [1] uv_error at .\libuv.jl:85 [inlined]
│  [3] #rm#9(::Bool, ::Bool, ::Function, ::String) at .\file.jl:253
│  [4] #rm at .\tuple.jl:0 [inlined]
│  [5] #uninstall#136(::Bool, ::Function, ::String) at C:\Users\cstamas\.julia\packages\BinaryProvider\4F5Hq\src\Prefix.jl:390
│  [6] #uninstall at .\none:0 [inlined]
│  [7] #install#133(::Prefix, ::String, ::Bool, ::Bool, ::Bool, ::Function, ::String, ::String) at C:\Users\cstamas\.julia\packages\BinaryProvider\4F5Hq\src\Prefix.jl:324
│  [8] (::getfield(BinaryProvider, Symbol("#kw##install")))(::NamedTuple{(:prefix, :force, :verbose),Tuple{Prefix,Bool,Bool}}, ::typeof(install), ::String, ::String) at .\none:0
│  [9] top-level scope at C:\Users\cstamas\.julia\packages\ImageMagick\d5KBL\deps\build_libpng.v1.0.0.jl:36
│  [10] include at .\boot.jl:326 [inlined]
│  [11] top-level scope at C:\Users\cstamas\.julia\packages\ImageMagick\d5KBL\deps\build.jl:15 [inlined]
│  [12] top-level scope at .\none:0
│  [13] include at .\boot.jl:326 [inlined]
│  [15] include(::Module, ::String) at .\sysimg.jl:29
│  [16] include(::String) at .\client.jl:403
│  [17] top-level scope at none:0
│ in expression starting at C:\Users\cstamas\.julia\packages\ImageMagick\d5KBL\deps\build_libpng.v1.0.0.jl:32
│ in expression starting at C:\Users\cstamas\.julia\packages\ImageMagick\d5KBL\deps\build.jl:11
Building SpecialFunctions → `C:\Users\cstamas\.julia\packages\SpecialFunctions\fvheQ\deps\build.log`
Building Homebrew ────────→ `C:\Users\cstamas\.julia\packages\Homebrew\s09IX\deps\build.log`
Building CMake ───────────→ `C:\Users\cstamas\.julia\packages\CMake\ZGawK\deps\build.log`
Building GLFW ────────────→ `C:\Users\cstamas\.julia\packages\GLFW\69NQ7\deps\build.log`
Building GLMakie ─────────→ `C:\Users\cstamas\.julia\packages\GLMakie\nDrlO\deps\build.log`

(v1.1) pkg> up
Updating registry at `C:\Users\cstamas\.julia\registries\General`
Updating git-repo `https://github.com/JuliaRegistries/General.git`
Resolving package versions...
Installed LoweredCodeUtils ─ v0.3.4
Installed ImageMagick ────── v0.7.3
Installed DataFrames ─────── v0.18.0
Updating `C:\Users\cstamas\.julia\environments\v1.1\Project.toml`
[6218d12a] ↑ ImageMagick v0.7.1 ⇒ v0.7.3
Updating `C:\Users\cstamas\.julia\environments\v1.1\Manifest.toml`
[a93c6f00] ↑ DataFrames v0.17.1 ⇒ v0.18.0
[6218d12a] ↑ ImageMagick v0.7.1 ⇒ v0.7.3
[6f1432cf] ↑ LoweredCodeUtils v0.3.3 ⇒ v0.3.4
Building ImageMagick → `C:\Users\cstamas\.julia\packages\ImageMagick\J74FC\deps\build.log`

(v1.1) pkg> build Makie
Building FreeType ────────→ `C:\Users\cstamas\.julia\packages\FreeType\2dE5w\deps\build.log`
Building Conda ───────────→ `C:\Users\cstamas\.julia\packages\Conda\CpuvI\deps\build.log`
Building FFTW ────────────→ `C:\Users\cstamas\.julia\packages\FFTW\p7sLQ\deps\build.log`
Building ImageMagick ─────→ `C:\Users\cstamas\.julia\packages\ImageMagick\J74FC\deps\build.log`
Building SpecialFunctions → `C:\Users\cstamas\.julia\packages\SpecialFunctions\fvheQ\deps\build.log`
Building Homebrew ────────→ `C:\Users\cstamas\.julia\packages\Homebrew\s09IX\deps\build.log`
Building CMake ───────────→ `C:\Users\cstamas\.julia\packages\CMake\ZGawK\deps\build.log`
Building GLFW ────────────→ `C:\Users\cstamas\.julia\packages\GLFW\69NQ7\deps\build.log`
Building GLMakie ─────────→ `C:\Users\cstamas\.julia\packages\GLMakie\nDrlO\deps\build.log`

julia> exit()

C:\Users\cstamas\Documents\Coding\makieplot>julia
_
_       _ _(_)_     |  Documentation: https://docs.julialang.org
(_)     | (_) (_)    |
_ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` |  |
| | |_| | | | (_| |  |  Version 1.1.0 (2019-01-21)
_/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> include("arrowsonsphere.jl")
[ Info: Recompiling stale cache file C:\Users\cstamas\.julia\compiled\v1.1\AbstractPlotting\6fydZ.ji for AbstractPlotting [537997a7-5e4e-5d89-9595-2241ea00577e]
Scene (800px, 450px):
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:

julia>
``````

Another issue that I encountered on my other machine is, that this examples works from the REPL but not in Atom. Is there any known issue related to Makie with Atom?