# Density Distributions

**URL:** <https://discourse.julialang.org/t/density-distributions/52224>\
**Category:** Statistics\
**Tags:** plotting, distributions\
**Created:** [December 22, 2020, 11:25am UTC](https://discourse.julialang.org/t/density-distributions/52224 "2020-12-22T11:25:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lorrp1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lorrp1/32/17647_2.png) [@lorrp1](https://discourse.julialang.org/u/lorrp1)\
**Post date:** [December 22, 2020, 11:25am UTC](https://discourse.julialang.org/t/density-distributions/52224/1 "2020-12-22T11:25:24Z")

</div>

Hello, im trying to get the array of the discrete probability distribution of a normal distribution:

i have tried:

```julia
d = Normal() #standard
a = rand(d,1000)
x = pdf.(d, a) #even with just pdf(d,a)
plot(x)

```

but its not working

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [December 22, 2020, 11:36am UTC](https://discourse.julialang.org/t/density-distributions/52224/2 "2020-12-22T11:36:00Z")

</div>

first do  
`using Distributions, Plots`  
then your code works on my Julia 1.5.3 (Windows)

---

<div class="post-metadata">

**Author:** ![lorrp1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lorrp1/32/17647_2.png) [@lorrp1](https://discourse.julialang.org/u/lorrp1)\
**Post date:** [December 22, 2020, 11:37am UTC](https://discourse.julialang.org/t/density-distributions/52224/3 "2020-12-22T11:37:49Z")

</div>

can you post what it is returning you (the plot)?

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [December 22, 2020, 11:43am UTC](https://discourse.julialang.org/t/density-distributions/52224/4 "2020-12-22T11:43:30Z")

</div>

I don’t know what you expect, but if you change your code to

```julia
using Distributions, Plots
d = Normal() #standard
x = sort!(rand(d,1000))
y = pdf(d, x) #even with just pdf(d,a)
plot(x,y)

```

I see a nice approximation of a gaussian bell curve.

---

<div class="post-metadata">

**Author:** ![lorrp1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lorrp1/32/17647_2.png) [@lorrp1](https://discourse.julialang.org/u/lorrp1)\
**Post date:** [December 22, 2020, 11:57am UTC](https://discourse.julialang.org/t/density-distributions/52224/5 "2020-12-22T11:57:32Z")

</div>

thanks thats what i wanted, i dont understand why using sort!() works though

---

<div class="post-metadata">

**Author:** ![Paul\_Soderlind](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paul_soderlind/32/1753_2.png) [@Paul\_Soderlind](https://discourse.julialang.org/u/Paul_Soderlind)\
**Post date:** [December 22, 2020, 12:08pm UTC](https://discourse.julialang.org/t/density-distributions/52224/6 "2020-12-22T12:08:28Z")

</div>

> i dont understand why using sort!() works though

for plotting a series, you want `x` to be ordered (typically increasing order)

---

<div class="post-metadata">

**Author:** ![Rudi79](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rudi79/32/3884_2.png) [@Rudi79](https://discourse.julialang.org/u/Rudi79)\
**Post date:** [December 22, 2020, 12:28pm UTC](https://discourse.julialang.org/t/density-distributions/52224/7 "2020-12-22T12:28:25Z")

</div>

I intentionally changed the names of your variables. Think about a function f(x) = x You basically told Julia to roll a dice several times and plot the result. Assume you rolled x={2,-1,3}. Plotting x in that order clearly is not the graph of f. Ordering the arguments gives the correct result.  
In the same spirit, you could change

```julia
x=sort!(rand(d,1000))

```

to

```julia
x=-3:0.1:3

```

and plot the result. But of course it is still unclear what you wanted to achieve in the first place.  
Note that there is not a clear notion of a discrete normal distribution. And hence the terminology of getting the one array of the probabliity distribution is also a bit unclear.
