Plotting of PDF of distributions not returning correct plot

Using the following code:

using Distributions

dist = Normal() 


The plot returns as

The x-axis values are incorrect, is there a reason is it not centred at 0 as it should be?

Should be noted if I do something such as


then it will return the correct plot.

You essentially have


In that case the xaxis is the index number into the array. You need something like plot(xarray, yarray), i.e.

x = collect(-2.0:0.1:2.0)
plot(x, pdf.(dist, x))

Alternatively you can plot a function in a range with Plots.jl via

pdf_eval(x) = pdf(dist, x)
plot(pdf_eval, -2, 2)

plot(x->pdf(dist,x), -2, 2)

Or, using the Distribution recipe implemented StatsPlots:

using StatsPlots, Distributions
1 Like