  C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD # Smoothening a normal/gaussian plot in matplotlib  » python » Smoothening a normal/gaussian plot in matplotlib

By : Dmitry
Date : November 22 2020, 10:33 AM
I think the issue was by ths following , I tried to reproduce your array with the following code. a is your array. code :
``````import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab

a = np.random.randn(500)*5
plt.plot(a, mlab.normpdf(a, np.mean(a), np.std(a)))
plt.show()
``````
``````n = mlab.normpdf(a, np.mean(a), np.std(a))
ind = np.argsort(a)
a = a[ind]
n = n[ind]
plt.plot(a,n)
plt.show()
``````
``````plt.plot(a, mlab.normpdf(a, np.mean(a), np.std(a)), 'o')
`````` ## Trying to plot multivariate Gaussian dist. in a 3D plot matplotlib returns an empty figure

By : ww.li
Date : March 29 2020, 07:55 AM
I wish this helpful for you I'm no expert with 3D-plots in matplotlib, but I believe your data wrong.
As you can see in the sourcecode in this tutorial, your X,Y and Z data have to be 2-dimensional arrays. Your X and Y are one-dimensional, and your Z is a simple list. ## Matplotlib: Plot path integral of curve under bivariate gaussian

By : barataatomica
Date : March 29 2020, 07:55 AM
To fix this issue I am trying to plot the path (or line) integral under a (negative log) bivariate gaussian. I am aiming to produce something that looks like the different stages of this neat little gif I found a wikipedia.
code :
``````import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.mlab import bivariate_normal
import scipy.interpolate

def func(X, Y):
# Bivariate gaussian
return -np.log(bivariate_normal(X, Y))

sns.set(style="white", palette="muted", color_codes=True)

def create_smoth_path(points):
data = np.array(points).T

tck, u = scipy.interpolate.splprep(data, s=0)
unew = np.arange(0, 1.01, 0.01)
out = scipy.interpolate.splev(unew, tck)
return out

def pathIntegral(path, func_):
x = path
y = path
z = func_(x, y)
z1 = np.zeros((2, x.shape))
z1 = z

x1 = np.tile(x, (2, 1))
y1 = np.tile(y, (2, 1))

start = min(x.min(), y.min())-2
stop = max(x.max(), y.max())+2
a = np.arange(start, stop, 0.5)
b = a
X, Y = np.meshgrid(a, b)
Z = func_(X, Y)

ax = plt.subplot2grid((3,1), (0,0), rowspan=2, projection='3d')
ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.cm.gist_heat_r, alpha=0.2, linewidth=0.1)

ax.plot_surface(x1, y1, z1, rstride=1, cstride=1, color='g')
ax.scatter(x, y, 0, c='k', marker='o')
ax.scatter(x[-1], y[-1], 0, c='k', marker='o')
ax.plot(x1, y1, color='b')
dx = np.diff(x)
dy = np.diff(y)
dr = np.sqrt(dx**2 + dy**2)
r = np.concatenate((np.zeros(1), np.cumsum(dr)))
ax = plt.subplot2grid((3,1), (2,0))
ax.set_xlim([np.min(r), np.max(r)])
plt.plot(r, z, 'r')
plt.xlabel('r')
plt.ylabel('z(x, y)')
plt.show()

# path
points = [(-5, -6), (-1, -3), (1, -2), (2, 1), (0, 0), (2, 2), (4, 3), (4, 3.5), (5, 5)]

r = create_smoth_path(points)
pathIntegral(r, func)
`````` ## Plot a bivariate gaussian using Matplotlib

By : fang
Date : March 29 2020, 07:55 AM
like below fixes the issue Your problem is not actually with the spatial extent of your probability distribution functions, but rather with the normalisation you use to display your composition functions. In particular, as a value of zero should mean zero probability and it is of course favourable if that value is tied to the same colour in each frame. The normalisation you use in your code, namely
code :
``````normPDF = PDF - PDF.min()
normPDF = normPDF / normPDF.max()
``````
``````normPDF = (PDFs-PDFs)/max(PDFs.max(),PDFs.max())
``````
``````cfs = ax.contourf(X, Y, normPDF, cmap='viridis', alpha = 1, levels=np.linspace(-1,1,10))
`````` ## how to plot 3d gaussian distribution with matplotlib

By : varun kumar
Date : March 29 2020, 07:55 AM
may help you . this is based on documentation of mpl_toolkits and an answer on SO based on scipy multinormal pdf ## How to plot the pdf of a 1D Gaussian Mixture Model with matplotlib

By : Sumit
Date : March 29 2020, 07:55 AM
I wish this helpful for you You can literally draw samples from a Gaussian mixture model and plot the empirical density / histogram too: 