Search code examples
plotjuliamakie.jl

In Makie.jl how to avoid overlapping axis elements in repeated plot?


How do I avoid the overlapping elements in the axis when plotting multiple times (e.g. in a for loop) in Makie?

For example, here I'd like to show the many density lines, but the y-axis has overlapping elements. Why does this occur and how do I prevent it from happening?

f = Figure()
for i in 1:10
    ax = Axis(f[1, 1])
    density!(rand(20), color = (:red, 0.0),
strokecolor = :red, strokewidth = 1, strokearound = false)
    xlims!(0.0,1.0)
end
f

Produces: enter image description here


Solution

  • Create the axis once and use it as the first argument to density!:

    f = Figure()
    ax = Axis(f[1, 1])
    xlims!(ax, 0.0, 1.0)
    for i in 1:10
        density!(ax, rand(20), color = (:red, 0.0),
            strokecolor = :red, strokewidth = 1, strokearound = false)
    end
    f