0

I have 2 probability density functions pdf1, pdf2. I need to use them to calculate the joint probability, and display it like this:

enter image description here

i've tried using plot_surface, but I couldn't figure out how to calculate the parameters X,Y,Z

import numpy as np
from matplotlib import pyplot as plt
from scipy.stats import norm

x1 = norm.rvs(size=1000)
x2 = list(map(lambda val: val if abs(val)<=1 else -val, x1))

samples = np.linspace(-5, 5, 100)
pdf1 = norm.pdf(samples, np.mean(x1), np.std(x1))
pdf2 = norm.pdf(samples, np.mean(x2), np.std(x2))
X,Y = np.meshgrid(pdf1,pdf2)

fig = plt.figure(figsize =(12, 12))
ax = plt.axes(projection ='3d')
ax.plot_surface(X,Y,?)

plt.show()

Would appreciate any help!

DanielG
  • 217
  • 2
  • 6
  • Isn't a joint probability a mesure from a 2D space ? In your code, `X` and `Y` are independant 1D normal distribution, which make no sense. Furthermore, if you want to plot a R^2 => R function, `X` and `Y` should be a plane – Zelemist Nov 13 '22 at 19:27
  • If your distribution are independant, then `X` and `Y` are a range (maybe -2 to 2 ?) and `Z = pdf1 * pdf2` – Zelemist Nov 13 '22 at 19:29

0 Answers0