# Plot! function does not plot the right distribution

**URL:** <https://discourse.julialang.org/t/plot-function-does-not-plot-the-right-distribution/33635>\
**Category:** General Usage\
**Created:** [January 21, 2020, 8:19pm UTC](https://discourse.julialang.org/t/plot-function-does-not-plot-the-right-distribution/33635 "2020-01-21T20:19:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lixiang\_Wei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lixiang_wei/32/11462_2.png) [@Lixiang\_Wei](https://discourse.julialang.org/u/Lixiang_Wei)\
**Post date:** [January 21, 2020, 8:19pm UTC](https://discourse.julialang.org/t/plot-function-does-not-plot-the-right-distribution/33635/1 "2020-01-21T20:19:56Z")

</div>

Hi,  
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:  
 ![plot](https://global.discourse-cdn.com/julialang/original/3X/4/a/4a7fc820d1377a2043e414c1e7e5513b0fe70634.png)  
using Plots  
x = rand(Normal(10, sqrt(2)), 10000)  
histogram(x)  
plot!(Normal(10,sqrt(2)))

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [January 21, 2020, 8:43pm UTC](https://discourse.julialang.org/t/plot-function-does-not-plot-the-right-distribution/33635/2 "2020-01-21T20:43:53Z")

</div>

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)`

---

<div class="post-metadata">

**Author:** ![Lixiang\_Wei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lixiang_wei/32/11462_2.png) [@Lixiang\_Wei](https://discourse.julialang.org/u/Lixiang_Wei)\
**Post date:** [January 21, 2020, 8:52pm UTC](https://discourse.julialang.org/t/plot-function-does-not-plot-the-right-distribution/33635/4 "2020-01-21T20:52:26Z")

</div>

Thanks, and this is the issue, I need to add normalize = true in my histogram.  
Thank you!

---

<div class="post-metadata">

**Author:** ![pbayer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pbayer/32/11675_2.png) [@pbayer](https://discourse.julialang.org/u/pbayer)\
**Post date:** [January 21, 2020, 9:12pm UTC](https://discourse.julialang.org/t/plot-function-does-not-plot-the-right-distribution/33635/5 "2020-01-21T21:12:22Z")

</div>

or scale the pdf to sum(y)/nbins:

```julia
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)

```

![gauss](https://global.discourse-cdn.com/julialang/original/3X/f/d/fd61e6040e71c7f929bfc8905b96063afcd8f67a.png)
