1

I've generated a 2D Guassian distribution with matplotlib.pyplot.hist2d. What I'd like to know is if there is any function in Python that allows me to caluclate and plot the integral and derivative of a 2D histogram. Checking on internet I've found a lot of topics about this, but only for 1D distribution.

Could anyone help me?

This is my code:

import numpy as np
import matplotlib.pyplot as plt

#GENERATE 2 RANDOM GAUSSIAN DISTRIBUTION
mu1, sigma1 = 0, 0.1                                  
s1 = np.random.normal(mu1, sigma1, 10000)              
mu2, sigma2 = 0, 0.3
s2 = np.random.normal(mu2, sigma2, 10000)

#PLOT 2 RANDOM GAUSSIAN DISTRIBUTION
plt.figure(1)
plt.title('Histogram of a 2D-Gaussian Distribution')
plt.xlabel('Radial position')
plt.ylabel('Particle frequency')
bins1 = plt.hist(s1, 100)          
bins2 = plt.hist(s2, 100)
plt.show()

#GENERATE AND PLOT 2D RANDOM GAUSSIAN DISTRIBUTION
plt.figure(2)
plt.title('2D-Gaussian Distribution')
bins = plt.hist2d(s1, s2, 100)          
cb = plt.colorbar()
cb.set_label('counts in bin')
#plt.axis('equal')
plt.show()

Thanks!

XaBla
  • 127
  • 1
  • 1
  • 8
  • Did you check this: https://stackoverflow.com/a/29975271/6198978 – NoorJafri May 25 '18 at 12:30
  • Sure! I'm new in Python, but I understand that what you have post is for a a 1D histogram, infact he uses "fig = plt.hist(x, bins)", on the contrary I've generated 2 different random Gaussian distribution, and I've used "bins = plt.hist2d(s1, s2, 100)" to plot the 2D histogram. – XaBla May 25 '18 at 12:37
  • First, how do you know it is a 2D Gaussian distribution, if you just have a histogram? You could use your data to estimate a 2d Gaussian pdf by computing means and covariance matrix. Then it makes sense to compute integrals or derivatives of this pdf. – CodeZero May 25 '18 at 12:46
  • I know it's a 2D Gaussian distribution becausa I've generated it generating two 1D random gaussian distribution and then using the function I've already posted you above to generate the 2D distribution. Maybe it would be usefull to edit the question I've made with the code I've implemented, so that you can better understand what I'm speaking about. – XaBla May 25 '18 at 13:01
  • Oups, my maths are now rather old, but what to you call derivative of a 2D distribution? The 2 partial derivatives or the vectorial gradiant? – Serge Ballesta May 25 '18 at 14:56

0 Answers0