The problem in my particular use case is that the horizontal line spans the entire x-axis. Is there a way to plot hspan as a line between xmin and xmax?
Ah my apologies, I didn’t read closely enough then - no I don’t believe that’s possible, vspan and hspan are specifically made for spanning the entire plot range vertically/hoirzontally
For completeness, here is an adaption of the solution above for vertical lines. It draws a vertical line extending to the curve of a normal PDF to show the density at particular x values.
using Plots, Distributions
# add density lines
x = -3:.05:3
y = pdf.(Normal(0,1), x)
x_line = [.6,1,1.8]
plot(x, y)
density_max = pdf.(Normal(0,1), x_line)
density_min = fill(0.0, length(x_line))
plot!(x_line', [density_min';density_max'], color=:black)
As a side note, the syntax of your last line works with pyplot() back-end but does not produce the expected results with the gr() back-end for instance. The following works for both: