An illustration of Julia's beautiful design via truncated normal plots using StatsPlot.jl and Distributions.jl

I was going to give a talk on a topic involving truncated normal distributions and I decided to write it in Julia. I googled how to do a density plot and quickly found an example for plotting the density of a normal function

using StatPlots
using Distributions
plot(Normal(3,5), fill=(0, .5,:orange))

Great. But how do I do a truncated one? I search for truncated normal and found it in Distributions.jl with a beautifully simple API Truncated(d, l, u), so I did

plot(Truncated(Normal(0,1), -1, 1.2), fill=(0, .5,:orange), xlim = (-2,2))

and viola!

I remember doing this in R and I don’t remember it as this easy! And R is by statisticians for statisticians!

I think this is a great illustration of the expressive power of Julia as a language and, in particular, for general statistical work!

17 Likes