title: 2D Density or Frquency Scatter Plot in python
body: <p>How can I make a scatter plot colored by density in matplotlib? 
  When I plot a colorbar it shows density scale, I want counts/percentage instead. How to convert density estimation to frequency counts?</p>
  
  <p>Expected result is Fig.3 on page 8 of this paper: <a href="https://www.atmos-meas-tech.net/9/3293/2016/amt-9-3293-2016.pdf" rel="nofollow noreferrer">https://www.atmos-meas-tech.net/9/3293/2016/amt-9-3293-2016.pdf</a> </p>
  
  <p>If anyone can guide me to draw a plot similar to one shown in paper, it will be really helpful. Thank you in advance.</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  from scipy.stats import gaussian_kde
  
  # Generate fake data
  x = np.random.normal(size=1000)
  y = x * 3 + np.random.normal(size=1000)
  
  # Calculate the point density
  xy = np.vstack([x,y])
  z = gaussian_kde(xy)(xy)
  
  fig, ax = plt.subplots()
  cax=ax.scatter(x, y, c=z, s=10, cmap=plt.cm.jet)
  cbar = fig.colorbar(cax)
  plt.show()
  </code></pre>
  
  <p>Another Method Tried:</p>
  
  <pre><code>#libraries
  import matplotlib.pyplot as plt
  import numpy as np
  from scipy.stats import kde
  
  # create data
  x = np.random.normal(size=500)
  y = x * 3 + np.random.normal(size=500)
  
  
  # Evaluate a gaussian kde on a regular grid of nbins x nbins over
  nbins=50
  k = kde.gaussian_kde([x,y])
  xi, yi = np.mgrid[min(x):max(x):nbins*1j, min(y):max(y):nbins*1j]
  zi = k(np.vstack([xi.flatten(), yi.flatten()]))
  
  # Add color bar
  plt.pcolormesh(xi, yi, zi.reshape(xi.shape), cmap=plt.cm.jet)
  plt.colorbar()
  plt.show() 
  </code></pre>