I’m currently converting some code from MATLAB to Julia, and have reached the stage where I have to do some graphics.
The picture shows the MATLAB plot on the right and my attempt in Julia using Makie.jl on the left. I’m almost there but I have some problems.
- I need to turn off the axes, grid and labels on the bottom two plots.
- The title refuses to appear on the top plot
- I need to add colorbars to the bottom two plots.
- Using ‘axis image’ in MATLAB the plot on the right has the coins that stay in proportion when the plot is resized. The Makie plot distorts the coins when I resize the window.
Any help gratefully received. My code is below. I’ve cut and pasted it as is, so there’s lots of crap in there, but I hope my feeble attempts at using Makie are clear. Be kind. This is my first attempt.
function solplot(sol::Solution)
x = vec(collect(range(0.0, sol.target.LX, length = sol.target.NX)))
y = vec(collect(range(0.0, sol.target.LY, length = sol.target.NY)))
Zrange = sol.Zmax - sol.Zmin
if Zrange == 0.0
title1 = @sprintf(
"RMS error = %2.2f%s.",
1000 * sol.err * sol.beamparams.beamdiameter,
"μ"
)
else
title1 = @sprintf(
"RMS error = %2.2f%sm (%2.1f%s).",
1000 * sol.err * sol.beamparams.beamdiameter,
"μ",
100 * sol.err * sol.beamparams.beamdiameter / Zrange,
"%"
)
end
scene1 = Makie.heatmap(
x,
y,
-1000.0 * sol.beamparams.beamdiameter .* sol.Z,
colormap = :bone,
axis = (names = (title = title1,),),
)
t = vec(collect(range(0.0, 2π, length = 30)))
Makie.lines!(
scene1,
(sol.target.LX .- 0.5 .* (1.0 .+ cos.(t))),
sol.target.LY .- 0.5 .* (1.0 .+ sin.(t)),
color = :red,
)
if Zrange == 0.0
title2 = @sprintf(
"Target mean depth = %2.1f%sm",
-1000 * sol.beamparams.beamdiameter * minimum(sol.Ztarget[:]),
"μ"
)
elseif sol.Zmax != 0
title2 = @sprintf(
"Target depth range = %2.1f%sm",
1000 * sol.beamparams.beamdiameter * Zrange,
"μ"
)
else
title2 = @sprintf(
"Target depth = %2.1f%sm",
1000 * sol.beamparams.beamdiameter * Zrange,
"μ"
)
end
scene2 = Makie.heatmap(
x,
y,
-1000.0 * sol.beamparams.beamdiameter .* sol.Ztarget,
colormap = :bone,
axis = (names = (title = title2,),),
)
Makie.lines!(
scene2,
(sol.target.LX .- 0.5 .* (1.0 .+ cos.(t))),
sol.target.LY .- 0.5 .* (1.0 .+ sin.(t)),
color = :red,
)
v = sol.beamparams.v0 ./ sol.D
s = sol.beamparams.beamdiameter .* sol.path.s
title3 = @sprintf(
"Target is %2.2f by %2.2f beam diameters (%2.2fmm by %2.2fmm)",
sol.target.LX,
sol.target.LY,
sol.target.LX * sol.beamparams.beamdiameter,
sol.target.LY * sol.beamparams.beamdiameter
)
scene3 = Makie.Scene()
for i = 1:size(sol.path.tracks)[1]
Makie.lines!(
scene3,
s[path.tracks[i, 1]:path.tracks[i, 2]+1],
v[path.tracks[i, 1]:path.tracks[i, 2]+1],
color = :black,
)
end
Makie.lines!(
scene3,
[s[1], s[end]],
[
sol.beamparams.v0 / sol.params.Dmin,
sol.beamparams.v0 / sol.params.Dmin,
],
color = :black,
linestyle = :dash,
)
Makie.lines!(
scene3,
[s[1], s[end]],
[
sol.beamparams.v0 / sol.params.Dmax,
sol.beamparams.v0 / sol.params.Dmax,
],
color = :black,
linestyle = :dash,
)
Makie.xlims!(scene3, 0.0, s[end])
Makie.ylims!(scene3, 0.0, 1.1 * sol.beamparams.v0 / sol.params.Dmin)
Makie.xlabel!(scene3, "Path distance (mm)")
Makie.ylabel!(scene3, "Feedrate (mm s⁻¹)")
Makie.title(scene3,title3)
scene = hbox(vbox(scene1, scene2), scene3)
display(scene)
end