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

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[0]
y = path[1]
z = func_(x, y)
z1 = np.zeros((2, x.shape[0]))
z1[1] = 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[0], y[0], 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[0]PDFs[1])/max(PDFs[0].max(),PDFs[1].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:

