title: Produce a RA vs DEC equatorial coordinates plot with python
body: <p>I'm trying to generate an equatorial coordinates plot that should look more or less like this one:</p>
  
  <p><img src="https://i.stack.imgur.com/gDNiE.png" alt="enter image description here"></p>
  
  <p>(The figure is taken from <a href="http://cdsads.u-strasbg.fr/abs/2008MNRAS.389..678B" rel="noreferrer">this article</a>, and it shows the position of the <a href="https://en.wikipedia.org/wiki/Magellanic_Clouds" rel="noreferrer">Large and Small MCs</a> in equatorial coordinates)</p>
  
  <p>Important things to notice about this plot:</p>
  
  <ul>
  <li>The <code>theta</code> axis (ie: the right ascension) is in <em>h:m:s</em> (hours, minutes, seconds) as it is accustomed in astronomy, rather than in degrees as the default <code>polar</code> option does in <code>matplotlib</code>.</li>
  <li>The <code>r</code> axis (ie: the declination) increases outward from -90º and the grid is centered in (0h, -90º).</li>
  <li>The plot is <strong>clipped</strong>, meaning only a portion of it shows as opposed to the entire circle (as <code>matplotlib</code> does by default).</li>
  </ul>
  
  <p>Using the <code>polar=True</code> option in <code>matplotlib</code>, the closest plot I've managed to produce is this (<code>MWE</code> below, data file <a href="http://pastebin.com/uJE5ARk9" rel="noreferrer">here</a>; some points are not present compared to the image above since the data file is a bit smaller):</p>
  
  <p><img src="https://i.stack.imgur.com/gGR4E.png" alt="enter image description here"></p>
  
  <p>I also need to add a third column of data to the plot, which is why I add a colorbar and color each point accordingly to a <code>z</code> array:</p>
  
  <p><img src="https://i.stack.imgur.com/bFzKX.png" alt="enter image description here"></p>
  
  <p>So what I mostly need right now is a way to clip the plot. Based mostly on <a href="https://stackoverflow.com/questions/27433310/how-to-clip-polar-plot-in-pylab-pyplot">this question</a> and <a href="http://matplotlib.org/mpl_toolkits/axes_grid/users/overview.html#curvilinear-grid" rel="noreferrer">this example</a> @cphlewis came quite close with <a href="https://stackoverflow.com/a/29556339/1391441">his answer</a>, but several things are still missing (mentioned in his answer).</p>
  
  <p>Any help and/or pointers with this issue will be greatly appreciated.</p>
  
  <hr>
  
  <p><strong>MWE</strong></p>
  
  <p>(Notice I use <code>gridspec</code> to position the subplot because I need to generate several of these in the same output image file)</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import matplotlib.gridspec as gridspec
  
  def skip_comments(f):
      '''
      Read lines that DO NOT start with a # symbol.
      '''
      for line in f:
          if not line.strip().startswith('#'):
              yield line
  
  def get_data_bb():
      '''RA, DEC data file.
      '''
  
      # Path to data file.
      out_file = 'bb_cat.dat'
  
      # Read data file
      with open(out_file) as f:
          ra, dec = [], []
  
          for line in skip_comments(f):
              ra.append(float(line.split()[0]))
              dec.append(float(line.split()[1]))
  
      return ra, dec
  
  # Read RA, DEC data from file.
  ra, dec = get_data_bb()
  # Convert RA from decimal degrees to radians.
  ra = [x / 180.0 * 3.141593 for x in ra]
  
  # Make plot.
  fig = plt.figure(figsize=(20, 20))
  gs = gridspec.GridSpec(4, 2)
  # Position plot in figure using gridspec.
  ax = plt.subplot(gs[0], polar=True)
  ax.set_ylim(-90, -55)
  
  # Set x,y ticks
  angs = np.array([330., 345., 0., 15., 30., 45., 60., 75., 90., 105., 120.])
  plt.xticks(angs * np.pi / 180., fontsize=8)
  plt.yticks(np.arange(-80, -59, 10), fontsize=8)
  ax.set_rlabel_position(120)
  ax.set_xticklabels(['$22^h$', '$23^h$', '$0^h$', '$1^h$', '$2^h$', '$3^h$',
      '$4^h$', '$5^h$', '$6^h$', '$7^h$', '$8^h$'], fontsize=10)
  ax.set_yticklabels(['$-80^{\circ}$', '$-70^{\circ}$', '$-60^{\circ}$'],
      fontsize=10)
  
  # Plot points.
  ax.scatter(ra, dec, marker='o', c='k', s=1, lw=0.)
  
  # Use this block to generate colored points with a colorbar.
  #cm = plt.cm.get_cmap('RdYlBu_r')
  #z = np.random.random((len(ra), 1))  # RGB values
  #SC = ax.scatter(ra, dec, marker='o', c=z, s=10, lw=0., cmap=cm)
  # Colorbar
  #cbar = plt.colorbar(SC, shrink=1., pad=0.05)
  #cbar.ax.tick_params(labelsize=8)
  #cbar.set_label('colorbar', fontsize=8)
  
  # Output png file.
  fig.tight_layout()
  plt.savefig(ra_dec_plot.png', dpi=300)
  </code></pre>