title: Plotting histogram with theoretical curve: Random realization
body: <p>I need to write a program that generates <strong>random realizations</strong> of the <strong>Cauchy distribution</strong> </p>
  
  <p><img src="https://latex.codecogs.com/gif.latex?f(x)=%5Cfrac%7B1%7D%7B%5Cpi%7B(1&plus;x%5E%7B2%7D)%7D%7D" title="f(x)=\frac{1}{\pi{(1+x^{2})}}" /></p>
  
  <p>with null location and unit scale.</p>
  
  <p>Also I need to make a histogram between -5 and 5 bins, for a random realization of 1,000 points, <strong>together with the theoretical curve</strong> making sure they have the same units. </p>
  
  <p>I calculated the cumulative distribution function  <img src="https://latex.codecogs.com/gif.latex?F(x)" title="F(x)" />  for the Cauchy distribution:</p>
  
  <p><img src="https://latex.codecogs.com/gif.latex?F(x)=tan[%7B%5Cpi%7B(rand()-%7B%5Cfrac%7B1%7D%7B2%7D)%7D%7D%7D]" title="F(x)=tan[{\pi{(rand()-{\frac{1}{2})}}}]" /></p>
  
  <p>And I wrote the following python code:</p>
  
  <p>
  </p>
  
  <pre><code>from __future__ import division
  import scipy
  import random
  import matplotlib.pyplot as plt
  import numpy as np
  import math as m
  
  
  valuesX = []
  for q in range(1000):
      R = random.random()
      x = m.tan(m.pi*(R-0.5)) #Cumulative Function
      valuesX.append(x)
  
  z = np.linspace(-10,10,1000)
  y = 1/(m.pi*(1+z**2)) #Theoretical Cauchy
  
  plt.plot(y,z)
  plt.hist(valuesX, bins = 50, range = [-5,5], normed=True)
  </code></pre>
  
  <p>My results were: <a href="https://i.stack.imgur.com/OKGNo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OKGNo.png" alt="Histogram of random realization for the Cauchy distribution"></a></p>
  
  <p>I don't know if this is acceptable since I'm plotting discrete values (random realization) against a probability density function. How could I compare the two of them? since I need to find the fractional difference for the plot above and determine the global rms deviations between both curves as a function of the size of the random realization.</p>