Skip to content


# MakieCore.meshFunction.
mesh(x, y, z)
mesh(x, y, z, faces)
mesh(xyz, faces)

Plots a 3D or 2D mesh. Supported mesh_objects include Mesh types from GeometryBasics.jl.

Plot type

The plot type alias for the mesh function is Mesh.



using GLMakie
vertices = [
    0.0 0.0;
    1.0 0.0;
    1.0 1.0;
    0.0 1.0;

faces = [
    1 2 3;
    3 4 1;

colors = [:red, :green, :blue, :orange]

scene = mesh(vertices, faces, color = colors, shading = NoShading)
using GLMakie
using FileIO

brain = load(assetpath("brain.stl"))

    color = [tri[1][2] for tri in brain for i in 1:3],
    colormap = Reverse(:Spectral)

Using GeometryBasics.Mesh and Buffer/Sampler type

We can also create a mesh, to specify normals, uv coordinates:

using GeometryBasics, LinearAlgebra, GLMakie, FileIO

# Create vertices for a Sphere
r = 0.5f0
n = 30
θ = LinRange(0, pi, n)
φ2 = LinRange(0, 2pi, 2 * n)
x2 = [r * cos(φv) * sin(θv) for θv in θ, φv in φ2]
y2 = [r * sin(φv) * sin(θv) for θv in θ, φv in φ2]
z2 = [r * cos(θv) for θv in θ, φv in 2φ2]
points = vec([Point3f(xv, yv, zv) for (xv, yv, zv) in zip(x2, y2, z2)])

# The coordinates form a matrix, so to connect neighboring vertices with a face
# we can just use the faces of a rectangle with the same dimension as the matrix:
faces = decompose(QuadFace{GLIndex}, Tesselation(Rect(0, 0, 1, 1), size(z2)))
# Normals of a centered sphere are easy, they're just the vertices normalized.
normals = normalize.(points)

# Now we generate UV coordinates, which map the image (texture) to the vertices.
# (0, 0) means lower left edge of the image, while (1, 1) means upper right corner.
function gen_uv(shift)
    return vec(map(CartesianIndices(size(z2))) do ci
        tup = ((ci[1], ci[2]) .- 1) ./ ((size(z2) .* shift) .- 1)
        return Vec2f(reverse(tup))

# We add some shift to demonstrate how UVs work:
uv = gen_uv(0.0)
# We can use a Buffer to update single elements in an array directly on the GPU
# with GLMakie. They work just like normal arrays, but forward any updates written to them directly to the GPU
uv_buff = Buffer(uv)
gb_mesh = GeometryBasics.Mesh(meta(points; uv=uv_buff, normals), faces)

f, ax, pl = mesh(gb_mesh,  color = rand(100, 100), colormap=:blues)
wireframe!(ax, gb_mesh, color=(:black, 0.2), linewidth=2, transparency=true)
record(f, "uv_mesh.mp4", LinRange(0, 1, 100)) do shift
    uv_buff[1:end] = gen_uv(shift)

The uv coordinates that go out of bounds will get repeated per default. One can use a Sampler object to change that behaviour:

Possible values:
:clamp_to_edge (default)
data = load(Makie.assetpath("earth.png"))
color = Sampler(rotl90(data'), x_repeat=:mirrored_repeat,y_repeat=:repeat)
f, ax, pl = mesh(gb_mesh,  color = color)
wireframe!(ax, gb_mesh, color=(:black, 0.2), linewidth=2, transparency=true)

record(f, "uv_mesh_mirror.mp4", LinRange(0, 1, 100)) do shift
    uv_buff[1:end] = gen_uv(shift)



Defaults to 1.0

The alpha value of the colormap or color attribute. Multiple alphas like in plot(alpha=0.2, color=(:red, 0.5), will get multiplied.


Defaults to 0.0

Sets a weight for secondary light calculation with inverted normals.


Defaults to @inherit patchcolor

Sets the color of the mesh. Can be a Vector{<:Colorant} for per vertex colors or a single Colorant. A Matrix{<:Colorant} can be used to color the mesh with a texture, which requires the mesh to contain texture coordinates.


Defaults to @inherit colormap :viridis

Sets the colormap that is sampled for numeric colors. PlotUtils.cgrad(...), Makie.Reverse(any_colormap) can be used as well, or any symbol from ColorBrewer or PlotUtils. To see all available color gradients, you can call Makie.available_gradients().


Defaults to automatic

The values representing the start and end points of colormap.


Defaults to identity

The color transform function. Can be any function, but only works well together with Colorbar for identity, log, log2, log10, sqrt, logit, Makie.pseudolog10 and Makie.Symlog10.


Defaults to [:color => :patchcolor]

No docs available.


Defaults to 0.0

adjusts the depth value of a plot after all other transformations, i.e. in clip space, where 0 <= depth <= 1. This only applies to GLMakie and WGLMakie and can be used to adjust render order (like a tunable overdraw).


Defaults to 1.0

Sets how strongly the red, green and blue channel react to diffuse (scattered) light.


Defaults to true

adjusts whether the plot is rendered with fxaa (anti-aliasing, GLMakie only).


Defaults to automatic

The color for any value above the colorrange.


Defaults to true

sets whether this plot should be seen by DataInspector.


Defaults to automatic

Sets a callback function (inspector, plot) -> ... for cleaning up custom indicators in DataInspector.


Defaults to automatic

Sets a callback function (inspector, plot, index) -> ... which replaces the default show_data methods.


Defaults to automatic

Sets a callback function (plot, index, position) -> string which replaces the default label generated by DataInspector.


Defaults to true

sets whether colors should be interpolated


Defaults to automatic

The color for any value below the colorrange.


Defaults to nothing

No docs available.


Defaults to nothing

RPRMakie only attribute to set complex RadeonProRender materials. Warning, how to set an RPR material may change and other backends will ignore this attribute


Defaults to automatic

Sets a model matrix for the plot. This overrides adjustments made with translate!, rotate! and scale!.


Defaults to :transparent

The color for NaN values.


Defaults to false

Controls if the plot will draw over other plots. This specifically means ignoring depth checks in GL backends


Defaults to automatic

Sets the lighting algorithm used. Options are NoShading (no lighting), FastShading (AmbientLight + PointLight) or MultiLightShading (Multiple lights, GLMakie only). Note that this does not affect RPRMakie.


Defaults to 32.0

Sets how sharp the reflection is.


Defaults to :data

sets the transformation space for box encompassing the plot. See Makie.spaces() for possible inputs.


Defaults to 0.2

Sets how strongly the object reflects light in the red, green and blue channels.


Defaults to false

Adjusts whether the plot is rendered with ssao (screen space ambient occlusion). Note that this only makes sense in 3D plots and is only applicable with fxaa = true.


Defaults to automatic

No docs available.


Defaults to false

Adjusts how the plot deals with transparency. In GLMakie transparency = true results in using Order Independent Transparency.


Defaults to true

Controls whether the plot will be rendered or not.