# Need help with highest posterior density interval plot using Makie

**URL:** <https://discourse.julialang.org/t/need-help-with-highest-posterior-density-interval-plot-using-makie/64320>\
**Category:** Visualization\
**Tags:** makie\
**Created:** [July 9, 2021, 4:52am UTC](https://discourse.julialang.org/t/need-help-with-highest-posterior-density-interval-plot-using-makie/64320 "2021-07-09T04:52:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![stochastic\_guy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stochastic_guy/32/9877_2.png) [@stochastic\_guy](https://discourse.julialang.org/u/stochastic_guy)\
**Post date:** [July 9, 2021, 4:52am UTC](https://discourse.julialang.org/t/need-help-with-highest-posterior-density-interval-plot-using-makie/64320/1 "2021-07-09T04:52:51Z")

</div>

I am trying to create the highest posterior density interval plot, but haven’t been able to create the one where the HDPI region is shaded and follows the density curve.

```julia
p_grid = range(0,stop=1,length=1000)
prior = fill(1,1000)
likelihood = pdf.(Binomial.(3,p_grid),3)
posterior = likelihood .* prior
posterior = posterior / sum(posterior)
samples = sample(p_grid, Weights(posterior),1000)
hd = hpdi(samples,alpha=0.5)

using Makie
x= samples[hd[1] .< samples .< hd[2]]
a = kde(x,npoints = 496)
lims1, lims2 = searchsortedfirst(x, -1), searchsortedlast(x, 1)
y = pdf(a,x)
fig = Figure()
ax = Axis(fig,xlabel="Proportion Water", ylabel="Density")
lines = Makie.density!(ax,samples, strokewidth=1, color=:transparent)
fillb = Makie. band!(ax,x[lims1:lims2], fill(0,length(x)),y; color = (:dodgerblue, 0.3))
fig[1,1] = ax
fig

```

The kind of plots I am getting are

 ![Screen Shot 2021-07-08 at 8.19.50 PM](https://global.discourse-cdn.com/julialang/original/3X/5/6/5618f9aeb9eb2635cf8529a1c9abd9ad12453c62.png)

---

<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:** [July 9, 2021, 7:49am UTC](https://discourse.julialang.org/t/need-help-with-highest-posterior-density-interval-plot-using-makie/64320/2 "2021-07-09T07:49:18Z")

</div>

```julia
k = kde(randn(100))

f, ax, l = lines(k)
band!(k.x[500:1500], zeros(1001), k.density[500:1500])
f

```

 ![grafik](https://global.discourse-cdn.com/julialang/original/3X/1/f/1f11df8b85adb119a8f21fe0dc3ee4ca8250eac6.png)

---

<div class="post-metadata">

**Author:** ![stochastic\_guy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stochastic_guy/32/9877_2.png) [@stochastic\_guy](https://discourse.julialang.org/u/stochastic_guy)\
**Post date:** [July 9, 2021, 1:43pm UTC](https://discourse.julialang.org/t/need-help-with-highest-posterior-density-interval-plot-using-makie/64320/3 "2021-07-09T13:43:15Z")

</div>

Thank You 😃
