I have a problem when using plot!, which should add a curve of Normal(10,2) fitting on my histogram. However, in my plot, I could see the label for plot!, it is overlapping on x-axis. I am using Mac, my friend is using Windows, and this issue is not reproduced on her machine. Code and output plot is attached below:
x = rand(Normal(10, sqrt(2)), 10000)
Are you sure this is the code you’re running? Which package versions are you on? For me,
plot(Normal(10, sqrt(2))) just errors.
In any case, this is an issue of scale - your y-axis goes up to 1,000, while the Normal cdf never goes above 1 (this is why it is squashed on the x-axis).
You probably want
histogram(rand(Normal(10, 2), 10_000), normalize = true)
Thanks, and this is the issue, I need to add normalize = true in my histogram.
or scale the pdf to sum(y)/nbins:
y = rand(Normal(10, sqrt(2)), 10000) x = 5:0.1:15 h = histogram(y, nbins=50) plot!(x, pdf.(Normal(10,sqrt(2)),x)*sum(y)/50)