title: Method to read data from a file when plot histogram with python?
body: <p>I ‘ve written a function to plot the histogram for an 1-D array theta . But one thing I do not like in this function is that the data  is in the code. Could you know how to keep the data in  a <em>file</em> and to make the function <em>read</em> them from the file?  Since the data is usually much larger.</p>
  
  <p>PS: The code is</p>
  
  <pre><code>#hist.py
  import matplotlib.mlab as mlab
  import matplotlib.pyplot as plt
  
  theta=[77.438110,82.811340,59.701530,124.94859,82.991272,84.300468,24.639610,112.28130]
  num_bins = 72
  # the histogram of the data 
  n, bins, patches = plt.hist(theta, num_bins, range=[0,180], normed = True,  histtype='bar',facecolor='green')
  plt.xlabel(r'$\theta$($\degree$)')
  plt.ylabel(r'$P(\theta)$')
  plt.show()
  </code></pre>