Following the idea of the link, I reproduced the graph using the Plots package, and I got the following questions:
It is possible to replace the following lines of code with a command:
subplot = plot!()[1]
h = extrema(Plots.axis_limits(subplot, :y))[2]
how to make the following lines of code run faster:
plot!(x->pdf(dist , x), xlim=xlims(),color=:red)
how to avoid that, in different runs, the density plot overlaps the annotation “median = …”?
full code
using Plots, Statistics, Distributions, Printf
dist = Normal(0, 1).+1
data = rand(dist, 1000)
plot(data,t=:histogram,normalize=true)
subplot = plot!()[1]
h = extrema(Plots.axis_limits(subplot, :y))[2]
m = median(data)
plot!([m],linetype=:vline,widths=3)
annotate!(m*1.1, h, Plots.text(string("median: ", @sprintf("%.0f", m)), :green, :left, 6))
#using Distributions
plot!(x->pdf(dist , x), xlim=xlims(),color=:red)
plot!(legend = false)