# Plotting of PDF of distributions not returning correct plot

**URL:** <https://discourse.julialang.org/t/plotting-of-pdf-of-distributions-not-returning-correct-plot/83421>\
**Category:** New to Julia\
**Tags:** statistics, plot\
**Created:** [June 27, 2022, 6:44pm UTC](https://discourse.julialang.org/t/plotting-of-pdf-of-distributions-not-returning-correct-plot/83421 "2022-06-27T18:44:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Max\_Beez](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Max\_Beez](https://discourse.julialang.org/u/Max_Beez)\
**Post date:** [June 27, 2022, 6:44pm UTC](https://discourse.julialang.org/t/plotting-of-pdf-of-distributions-not-returning-correct-plot/83421/1 "2022-06-27T18:44:22Z")

</div>

Using the following code:

```julia
using Distributions

dist = Normal() 

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

```

The plot returns as

 ![Screen Shot 2022-06-27 at 11.43.44 AM](https://global.discourse-cdn.com/julialang/original/3X/e/8/e86dc6c90c978b6d94da4b514dad191a229f0f67.png)

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

```julia
plot(x->exp(x),collect(-2:0.1:2)) 

```

then it will return the correct plot.

---

<div class="post-metadata">

**Author:** ![DrPapa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/drpapa/32/6835_2.png) [@DrPapa](https://discourse.julialang.org/u/DrPapa)\
**Post date:** [June 27, 2022, 6:57pm UTC](https://discourse.julialang.org/t/plotting-of-pdf-of-distributions-not-returning-correct-plot/83421/2 "2022-06-27T18:57:01Z")

</div>

You essentially have

```julia
plot(array)

```

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

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

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

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

```

---

<div class="post-metadata">

**Author:** ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)\
**Post date:** [June 27, 2022, 9:34pm UTC](https://discourse.julialang.org/t/plotting-of-pdf-of-distributions-not-returning-correct-plot/83421/3 "2022-06-27T21:34:13Z")

</div>

Or, using the Distribution recipe implemented StatsPlots:

```julia
using StatsPlots, Distributions
plot(Normal())

```
