If I understand correctly inset axes can be create rather easily in Makie by putting multiple axes in the same layout position. Something as follow:
fig = Figure(resolution=(500, 500))
# The main axis
density_ax = Axis(fig[1, 1],
backgroundcolor=:white)
# Some function plotting stuff
plot_densities!(density_ax, momenta[:, :, end, :])
# The inset axis
inset_ax = Axis(fig[1, 1],
width=Relative(0.5),
height=Relative(0.5),
halign=0.9,
valign=0.9,
backgroundcolor=:lightgray)
hidedecorations!(inset_ax)
# Some function plotting stuff
plot_densities!(inset_ax, momenta[:, :, end, :])
However it appears that the inset axis is drawn behind some elements of the main axis. For example in the following the grid and the contourf are drawn over the inset axis.
I tried to change the order in which I define the axis but it didn’t change much. How could I control that such that the inset axis would cover everyting drawn on the main axis?
The render order in this case is based on the z-value of each component. I’m not aware of a nice way to change this for the whole axis, but you can try this to move its components forward individually:
for (k, v) in inset_ax.elements
if v isa AbstractPlot
translate!(Accum, v, Vec3f0(0, 0, 200))
else
for (k, v2) in v.elements
translate!(Accum, v2, Vec3f0(0, 0, 200))
end
end
end
translate!(Accum, inset_ax.scene, Vec3f0(0, 0, 200))
fig = Figure(resolution=(500, 500))
# The main axis
density_ax = Axis(fig[1, 1],
backgroundcolor=:white)
# Some function plotting stuff
density!(density_ax, rand(1000))
# The inset axis
inset_ax = Axis(fig[1, 1],
width=Relative(0.5),
height=Relative(0.5),
halign=0.9,
valign=0.9,
backgroundcolor=:lightgray)
hidedecorations!(inset_ax)
translate!(inset_ax.scene, 0, 0, 10)
# this needs separate translation as well, since it's drawn in the parent scene
translate!(inset_ax.elements[:background], 0, 0, 9)
scatter!(inset_ax, 0..1, rand(4))
fig