title: Projection Problems when Displaying an Image on a Map with Cartopy
body: <p>I have some satellite image data I would like to display using Cartopy. I have successfully followed the image example detailed <a href="http://scitools.org.uk/cartopy/docs/v0.5/matplotlib/advanced_plotting.html" rel="noreferrer">here</a>. Resulting in this code:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import cartopy.crs as ccrs
  
  fig = plt.figure(figsize=(12, 12))
  img_extent = (-77, -59, 9, 26)
  
  ax = plt.axes(projection=ccrs.PlateCarree())
  # image data coming from server, code not shown
  ax.imshow(img, origin='upper', extent=img_extent)
  ax.set_xmargin(0.05)
  ax.set_ymargin(0.10)
  
  # mark a known place to help us geo-locate ourselves
  ax.plot(-117.1625, 32.715, 'bo', markersize=7)
  ax.text(-117, 33, 'San Diego')
  
  ax.coastlines()
  ax.gridlines()
  
  plt.show() 
  </code></pre>
  
  <p>This code generates the following image <img src="https://i.stack.imgur.com/mm16b.png" alt="wrong projection"></p>
  
  <p>My problem is that the satellite image data is not in the PlateCarree projection, but the Mercator projection.</p>
  
  <p>But when I get the axis object with </p>
  
  <pre><code>ax = plt.axes(projection=ccrs.Mercator())
  </code></pre>
  
  <p>I lose the coastlines.</p>
  
  <p><img src="https://i.stack.imgur.com/zGVH9.png" alt="no coastlines"></p>
  
  <p>I saw the issue reported <a href="https://github.com/SciTools/cartopy/issues/72" rel="noreferrer">here</a>. But</p>
  
  <pre><code>ax.set_global()
  </code></pre>
  
  <p>results in this image:</p>
  
  <p><img src="https://i.stack.imgur.com/yPOJo.png" alt="where is my data"></p>
  
  <p>The data is not present, and San Diego is in the wrong location. Also the lat/lon extents have changed. What am I doing wrong?</p>
  
  <p><strong>Post Discussion Update</strong></p>
  
  <p>The main problem is that I had not properly specified the image extents in the target projection with the <code>transform_points</code> method. I also had to be specific about the coordinate reference system in the <code>imshow</code> method as Phil suggests. Here is the correct code:</p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  import cartopy.crs as ccrs
  
  proj = ccrs.Mercator()
  fig = plt.figure(figsize=(12, 12))
  extents = proj.transform_points(ccrs.Geodetic(),
                                  np.array([-77, -59]),
                                  np.array([9, 26]))
  
  img_extents = (extents[0][0], extents[1][0], extents[0][6], extents[1][7] ) 
  
  ax = plt.axes(projection=proj)
  # image data coming from server, code not shown
  ax.imshow(img, origin='upper', extent=img_extents,transform=proj)
  
  ax.set_xmargin(0.05)
  ax.set_ymargin(0.10)
  
  # mark a known place to help us geo-locate ourselves
  ax.plot(-117.1625, 32.715, 'bo', markersize=7, transform=ccrs.Geodetic())
  ax.text(-117, 33, 'San Diego', transform=ccrs.Geodetic())
  
  ax.coastlines()
  ax.gridlines()
  
  plt.show() 
  </code></pre>
  
  <p>Resulting in this correctly geoprojected satellite image:</p>
  
  <p><img src="https://i.stack.imgur.com/7pulN.png" alt="correct image"></p>