3  Plotting

This chapter is utterly incomplete and probably not worth reading.

3.1 Plot a 1D mesh

3.1.1 On a straight line

m = Mesh(0 .. 4, 20)
mplot(m) |> mconf()

Nodes hidden if too many.

m = Mesh(0 .. 4, 60)
mplot(m) |> mconf()

One value per node

mplot(m, -1.1 .+ 2.6 * rand(nnodes(m))) |> mconf()

One value per element

mplot(m, -1.1 .+ 2.2 * rand(nedges(m))) |> mconf()

Two values per element

mplot(m, -1.1 .+ 2.2 * rand(2, nedges(m))) |> mconf()

3.1.2 Vertical

m = Mesh(π .. 3π, 20, t -> [0; t])
mplot(m, -1.1 .+ 3.2 * rand(nedges(m))) |> mconf()

3.1.3 On a spiral

m = Mesh(π .. 3π, 20, t -> t * [cos(t); sin(t)])
mplot(m, -1.1 .+ 3.2 * rand(2, nedges(m))) |> mconf()

3.1.4 Customize plot

Plot customization works like this:

f, ax = mplot(m, -1.1 .+ 3.2 * rand(2, nedges(m))) |> mconf()
ax.title = "Spiral with reversed vertical axis"
ax.yreversed = true
f

Documentation on plot axis can be found on the Makie documentation which unfortunately is quite hard to read.

3.2 Plot a 2D mesh

3.2.1 Quad mesh

a = 80
m = Mesh((0 .. 9.0) × (0 .. 4.5), 2a, a)
println("Number of nodes is Nn = ", (a + 1) * (2a + 1))
print("Links...")
@time l12 = links(m.topology, 1, 2);
Number of nodes is Nn = 13041
Links...  0.127076 seconds (1.12 M allocations: 87.086 MiB, 26.85% gc time, 21.03% compilation time)

Default color

mplot(m, edgesvisible=true, edgecolor=:hotpink) |> mconf()

Colors for nodes

mplot(m, 4.1 * (rand(nnodes(m)) .- 0.25)) |> mconf()

Colors for elements

mplot(m, 4.1 * (rand(nfaces(m)) .- 0.25)) |> mconf()

3.2.2 Triangle mesh

a = 20
m = Mesh((0 .. 9.0) × (0 .. 4.5), 2a, a, TRIANGLE)
println("Nn = ", (a + 1) * (2a + 1))
print("Links (1, 2):")
@time l12 = links(m.topology, 1, 2);
Nn = 861
Links (1, 2):  0.010145 seconds (103.33 k allocations: 8.277 MiB, 42.13% compilation time)

Default color

mplot(m, edgesvisible=true) |> mconf()

Colors for nodes

mplot(m, 4.1 * (rand(nnodes(m)) .- 0.25)) |> mconf()

Colors for elements

mplot(m, 4.1 * (rand(nfaces(m)) .- 0.25)) |> mconf()

3.3 Plot functions on meshes

3.3.1 Warp by nodal values

Nodes can be transformed. Either, specify a function which returns the warped coordinates of the node.

m = Mesh((0 .. 4) × (0 .. 2), 20, 10)
function warpfunction(node)
    x = coordinates(node)
    return [x..., 0.25 * sin(pi * (x[1] - 2)) * cos(pi * (x[2] - 1))]
end

f = Figure()
Axis3(f[1, 1], aspect=:data)
mplot!(m, rand(nfaces(m)), nodewarp=warpfunction)
f

Alternatively, use an array to perform a scalar warp.

m = Mesh((0 .. 4) × (0 .. 2), 10, 5)

f = Figure()
Axis3(f[1, 1], aspect=:data)
mplot!(m, rand(nfaces(m)), nodewarp=0.25 * rand(nnodes(m)))
f

3.3.2 Plot functions on faces

For each face, a function from the face geometry reference domain into the real numbers can be provided. Function values are visualized by colors and/or by warping the face.

The function is specified by the first parameter to the mplot function, settings are the faceplotXXX named parameters.

Method 1: Specify one function:

m = Mesh((0 .. 8) × (0 .. 4), 4, 2)
w(face) = x -> index(face) * (1 - x[1]^2) * (1 - x[2]^2)
f = Figure()
Axis3(f[1, 1], aspect=:data)
mplot!(m, w, faceplotzscale=0.2, faceplotmesh=2)
f

Method 2: Specify postprocessing function, here with the items w and sigma:

function results(face, name)
    if name == :w
        return x -> index(face) * (1 - x[1]^2) * (1 - x[2]^2)
    elseif name == :sigma
        s = Polynomial([0, π])
        return ProductFunction(Sin()  s, Cos()  s)
    end
end
setdata!(m, :post, results)

Plot result w:

f = Figure()
Axis3(f[1, 1], aspect=:data)
mplot!(m, :w, faceplotzscale=0.2, faceplotmesh=2)
f

Plot result sigma:

f = Figure()
Axis3(f[1, 1], aspect=:data)
mplot!(
    m, :sigma,
    faceplotzscale=0.5, faceplotmesh=15,
    edgelinewidth=2, edgecolor=:red, colormap=:redblue
)
f

3.4 Plot options

a = 10
m1 = Mesh((0 .. 4) × (0 .. 2), 2a, a)
mplot(m1, 3 * rand(nfaces(m1)),
    nodesvisible=true, nodecolor=:hotpink, nodesize=12,
    edgesvisible=true, edgecolor=:lightblue, edgelinewidth=3,
    featureedgecolor=:red, featureedgelinewidth=6,
    facecolormap=:bluesreds
) |> mconf()
m2 = Mesh(0 .. 4, 20)
mplot(m2, rand(nnodes(m2)),
    lineplotoutlinesvisible=true,
    edgecolor=:blue, edgelinewidth=10,
    lineplotscale=0.3,
    lineplotoutlinescolor=:hotpink,
    lineplotoutlineslinewidth=2.0,
    lineplotfacescolormap=:bluesreds
) |> mconf(title="Test Plot")