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

**URL:** <https://discourse.julialang.org/t/makie-make-only-part-of-a-violin-plot-transparent-with-correct-width/98196>\
**Category:** Visualization\
**Tags:** question, makie\
**Created:** [May 2, 2023, 1:06pm UTC](https://discourse.julialang.org/t/makie-make-only-part-of-a-violin-plot-transparent-with-correct-width/98196 "2023-05-02T13:06:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [May 2, 2023, 1:06pm UTC](https://discourse.julialang.org/t/makie-make-only-part-of-a-violin-plot-transparent-with-correct-width/98196/1 "2023-05-02T13:06:24Z")

</div>

Let’s take the following MWE:

```julia
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](https://global.discourse-cdn.com/julialang/original/3X/5/a/5a63473e28407aa39c0cf849871ce25d20aac598.png)

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?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [May 2, 2023, 3:52pm UTC](https://discourse.julialang.org/t/makie-make-only-part-of-a-violin-plot-transparent-with-correct-width/98196/2 "2023-05-02T15:52:44Z")

</div>

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

```julia
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()

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/f/0f275cde30c6c99f08b3ef2075373a761fd18d54.png)

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [May 3, 2023, 8:49am UTC](https://discourse.julialang.org/t/makie-make-only-part-of-a-violin-plot-transparent-with-correct-width/98196/3 "2023-05-03T08:49:47Z")

</div>

Thanks that’s good enough for me!!!

CU!

George Datseris (he/him)
