2019-08-13 20:12:49 8 Comments

I am trying to plot a truncated Gaussian distribution (using scipy) with a mean of `0.5`

, and a standard distribution of `1.0`

. The distribution is truncated to be only in the interval `(0,1)`

.

```
x = np.linspace(0,1,100)
dist=truncnorm(a=0,b=1,loc=0.5, scale = 1.0)
plt.plot(x, dist.pdf(x), 'k-', lw=2, label='normalised truncated Gaussian')
```

However I get this instead:

Everything after `x=0.5`

seems normal but below that you get a sudden dip to zero. However the distribution should only be zero outside of `(0,1)`

. What is going on and how do I fix it?

### Related Questions

#### Sponsored Content

#### 19 Answered Questions

### [SOLVED] Save plot to image file instead of displaying it using Matplotlib

**2012-03-08 17:38:10****Homunculus Reticulli****1343493**View**984**Score**19**Answer- Tags: python matplotlib plot

#### 10 Answered Questions

### [SOLVED] How to make IPython notebook matplotlib plot inline

**2013-10-16 17:34:42****Ian Fiske****979134**View**760**Score**10**Answer- Tags: python matplotlib jupyter-notebook ipython data-visualization

#### 16 Answered Questions

### [SOLVED] How to put the legend out of the plot

**2011-01-15 16:10:03****pottigopi****627519**View**806**Score**16**Answer- Tags: python matplotlib legend

#### 1 Answered Questions

#### 3 Answered Questions

### [SOLVED] scipy, lognormal distribution - parameters

**2012-01-05 18:29:08****Jakub M.****15652**View**24**Score**3**Answer- Tags: python statistics scipy

## 1 comments

## @Brennan 2019-08-13 20:53:44

You are telling it to plot that way with

`loc`

which shifts the plot.`dist=truncnorm(a=0,b=1,loc=0.5, scale = 1.0)`

should be`dist=truncnorm(a=0,b=1, scale = 1.0)`

to get the standard plot.From the source code on truncnorm():