= Mesh(0 .. 4, 20)
m mplot(m) |> mconf()
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
Nodes hidden if too many.
= Mesh(0 .. 4, 60)
m 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
= Mesh(π .. 3π, 20, t -> [0; t])
m mplot(m, -1.1 .+ 3.2 * rand(nedges(m))) |> mconf()
3.1.3 On a spiral
= Mesh(π .. 3π, 20, t -> t * [cos(t); sin(t)])
m mplot(m, -1.1 .+ 3.2 * rand(2, nedges(m))) |> mconf()
3.1.4 Customize plot
Plot customization works like this:
= mplot(m, -1.1 .+ 3.2 * rand(2, nedges(m))) |> mconf()
f, ax = "Spiral with reversed vertical axis"
ax.title = true
ax.yreversed 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
= 80
a = Mesh((0 .. 9.0) × (0 .. 4.5), 2a, a)
m 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
= 20
a = Mesh((0 .. 9.0) × (0 .. 4.5), 2a, a, TRIANGLE)
m 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.
= Mesh((0 .. 4) × (0 .. 2), 20, 10)
m function warpfunction(node)
= coordinates(node)
x return [x..., 0.25 * sin(pi * (x[1] - 2)) * cos(pi * (x[2] - 1))]
end
= Figure()
f Axis3(f[1, 1], aspect=:data)
mplot!(m, rand(nfaces(m)), nodewarp=warpfunction)
f
Alternatively, use an array to perform a scalar warp.
= Mesh((0 .. 4) × (0 .. 2), 10, 5)
m
= Figure()
f 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:
= Mesh((0 .. 8) × (0 .. 4), 4, 2)
m w(face) = x -> index(face) * (1 - x[1]^2) * (1 - x[2]^2)
= Figure()
f 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
= Polynomial([0, π])
s return ProductFunction(Sin() ∘ s, Cos() ∘ s)
end
end
setdata!(m, :post, results)
Plot result w
:
= Figure()
f Axis3(f[1, 1], aspect=:data)
mplot!(m, :w, faceplotzscale=0.2, faceplotmesh=2)
f
Plot result sigma
:
= Figure()
f Axis3(f[1, 1], aspect=:data)
mplot!(
:sigma,
m, =0.5, faceplotmesh=15,
faceplotzscale=2, edgecolor=:red, colormap=:redblue
edgelinewidth
) f
3.4 Plot options
= 10
a = Mesh((0 .. 4) × (0 .. 2), 2a, a)
m1 mplot(m1, 3 * rand(nfaces(m1)),
=true, nodecolor=:hotpink, nodesize=12,
nodesvisible=true, edgecolor=:lightblue, edgelinewidth=3,
edgesvisible=:red, featureedgelinewidth=6,
featureedgecolor=:bluesreds
facecolormap|> mconf() )
= Mesh(0 .. 4, 20)
m2 mplot(m2, rand(nnodes(m2)),
=true,
lineplotoutlinesvisible=:blue, edgelinewidth=10,
edgecolor=0.3,
lineplotscale=:hotpink,
lineplotoutlinescolor=2.0,
lineplotoutlineslinewidth=:bluesreds
lineplotfacescolormap|> mconf(title="Test Plot") )