Makie: Make only part of a violin plot transparent with correct width

Let’s take the following MWE:

using CairoMakie, Statistics

fig = Figure()
ax = Axis(fig[1,1])

Dloc = randn(1000)

# Full pdf
violin!(ax, fill(1, length(Dloc)), Dloc)

# Pdf plotted so that it is transparent after some value 
c = std(Dloc)
violin!(ax, fill(2, length(Dloc)), Dloc; color = "black", datalimits = (-Inf, c))
violin!(ax, fill(2, length(Dloc)), Dloc;
datalimits = (c, Inf), color = :transparent,
strokecolor = "black", strokewidth = 2,
)

fig

image

I would like to have the right violin, but with the transparent portion being the correct width, instead of being re-normalized from scratch. Is this possible?

I only know how to do it with the kde object directly:

using CairoMakie
using Makie.KernelDensity

data = randn(1000)
k = KernelDensity.kde(data)

cutoff = 0
mask = k.x .<= 0

band(k.x[mask], -k.density[mask], k.density[mask])
band!(k.x[.!mask], -k.density[.!mask], k.density[.!mask])
current_figure()

Thanks that’s good enough for me!!!

CU!

George Datseris (he/him)