Looking for a simple surface plot with Makie

This is what I tried:

using Makie, GeometryBasics, Colors

surface([0.0, 1.0, 2.0], [0.0, 1.0, 2.0], rand(9))

and I’m getting:

julia> surface([0.0, 1.0, 2.0], [0.0, 1.0, 2.0], rand(9))
ERROR: There was no `AbstractPlotting.convert_arguments` overload found for
the plot type Surface{...}, or its conversion trait AbstractPlotting.SurfaceLike().
The arguments were:
(Array{Float64,1}, Array{Float64,1}, Array{Float64,1})

To fix this, define `AbstractPlotting.convert_arguments(::Surface{...}, ::Array{Float64,1}, ::Array{Float64,1}, ::Array{Float64,1})`.

I can’t figure out from the documentation what parameter types are allowed. The example I cut and pasted from examples3d.jl:

    N = 30
    function xy_data(x, y)
        r = sqrt(x^2 + y^2)
        r == 0.0 ? 1f0 : (sin(r)/r)
    end
    r = range(-2, stop = 2, length = N)
    surf_func(i) = [Float32(xy_data(x*i, y*i)) for x = r, y = r]
    scene = surface(
        r, r, surf_func(10),
        color = rand(RGBAf0, 124, 124)
    )

produces a similar an error too.

I think the problem in your first example is that z is a vector and not a matrix. And in the second one z is a matrix which is good, but your color array has size (124, 124) while your x and y vectors have length 30.

1 Like

Thank you. Indeed, matrix makes more sense as the 3rd argument. This:

surface(1:3, 1:3, rand(3, 3))

works as intended. I just couldn’t parse the error message. The second example was copied from https://github.com/JuliaPlots/MakieGallery.jl/blob/master/examples/examples3d.jl