-1

If I generate a 1-D probability distribution and get a result like below: enter image description here

How can I convert this into a two-dimensional contourf plot, assuming the y-axis would be the same as the x-axis. Below, I created an image of what I would like the result to look like, where each band is repesentative of a range of probabilities. The bands would change with different x.

enter image description here

My code to generate the 1-D plot is below:

import matplotlib.pyplot as plt
import numpy as np

def gaussian(x, mu, sig):
    return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))

x_values = np.linspace(-5, 5, 120)
y = gaussian(x_values, 0, 1)

plt.figure()
plt.plot(x_values,y)
plt.show()
mj1496
  • 61
  • 1
  • 9

1 Answers1

0

Figured it out. The code is:

import matplotlib.pyplot as plt
import numpy as np

def gaussian(x, mu, sig):
    return np.exp(-np.power(x - mu, 2.) / (2 * np.power(sig, 2.)))

x_values = np.linspace(-5, 5, 120)
y_values = np.linspace(-5, 5, 120)
[xx,yy] = np.meshgrid(x_values,y_values)
 xx = np.concatenate(xx)
yy = np.concatenate(yy)

y = gaussian(xx, 0, 1)

plt.figure()
plt.contourf(x_values,y_values,y.reshape(len(x_values),len(y_values)))
plt.colorbar()
plt.show()

And it gives the result: enter image description here

mj1496
  • 61
  • 1
  • 9