#### [SOLVED] Plotting truncated normal distribution

By piccolo

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')
`````` 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? #### @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():

For a uniform distribution MLE, the location is the minimum of the data, and the scale is the maximum minus the minimum. (Line 6570)

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

• 2012-03-08 17:38:10
• Homunculus Reticulli
• 1448440 View
• 1064 Score
• Tags:   python matplotlib plot

### [SOLVED] In python, How to divide multivariate Gaussian distributions to separate Gaussians?

• 2019-02-21 16:33:54
• dina
• 136 View
• 1 Score
• Tags:   python numpy