Repository: SciTools/cartopy

Issue:
The GeoAxes subplot created with matplotlib is defined in matplotlib, not cartopy
When creating an axes with matplotlib, the axes appears to come from matplotlib, but it shouldn't.

```
In [1]: import cartopy.crs as ccrs
In [2]: import matplotlib.pyplot as plt
In [3]: type(plt.axes(projection=ccrs.PlateCarree()))
Out[3]: matplotlib.axes._subplots.GeoAxesSubplot
```

Ideally this should say: `cartopy.mpl.GeoAxesSubplot` and the class should have a _very_ short description in the cartopy docs.



Discussion:
All that would be needed would be to register a subplot subclass at around https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_subplots.py#L153. That is, there is a dictionary in matplotlib which stores all subclasses of subplot.


Resolving patch:
diff --git a/lib/cartopy/mpl/geoaxes.py b/lib/cartopy/mpl/geoaxes.py
--- a/lib/cartopy/mpl/geoaxes.py
+++ b/lib/cartopy/mpl/geoaxes.py
@@ -1549,6 +1549,15 @@ def add_wms(self, wms, layers, wms_kwargs=None, **kwargs):
         return self.add_raster(wms, **kwargs)
 
 
+# Define the GeoAxesSubplot class, so that a type(ax) will eminate from
+# cartopy.mpl.geoaxes, not matplotlib.axes.
+class GeoAxesSubplot(matplotlib.axes.SubplotBase, GeoAxes):
+    _axes_class = GeoAxes
+
+
+matplotlib.axes._subplot_classes[GeoAxes] = GeoAxesSubplot
+
+
 def _trigger_patch_reclip(event):
     """
     Defines an event callback for a GeoAxes which forces the outline and


Test patch:
diff --git a/lib/cartopy/tests/mpl/baseline_images/mpl/test_gridliner/gridliner_labels.png b/lib/cartopy/tests/mpl/baseline_images/mpl/test_gridliner/gridliner_labels.png
Binary files a/lib/cartopy/tests/mpl/baseline_images/mpl/test_gridliner/gridliner_labels.png and b/lib/cartopy/tests/mpl/baseline_images/mpl/test_gridliner/gridliner_labels.png differ
diff --git a/lib/cartopy/tests/mpl/baseline_images/mpl/test_img_transform/regrid_image.png b/lib/cartopy/tests/mpl/baseline_images/mpl/test_img_transform/regrid_image.png
Binary files a/lib/cartopy/tests/mpl/baseline_images/mpl/test_img_transform/regrid_image.png and b/lib/cartopy/tests/mpl/baseline_images/mpl/test_img_transform/regrid_image.png differ
diff --git a/lib/cartopy/tests/mpl/test_axes.py b/lib/cartopy/tests/mpl/test_axes.py
--- a/lib/cartopy/tests/mpl/test_axes.py
+++ b/lib/cartopy/tests/mpl/test_axes.py
@@ -20,6 +20,7 @@
 import unittest
 
 
+from matplotlib.testing.decorators import cleanup
 import matplotlib.path as mpath
 import matplotlib.pyplot as plt
 from nose.tools import assert_equal
@@ -84,6 +85,13 @@ def test_transform_PlateCarree_shortcut():
         assert_equal(counter.count, 2)
 
 
+@cleanup
+def test_geoaxes_subplot():
+    ax = plt.subplot(1, 1, 1, projection=ccrs.PlateCarree())
+    assert_equal(str(ax.__class__),
+                 "<class 'cartopy.mpl.geoaxes.GeoAxesSubplot'>")
+
+
 if __name__ == '__main__':
     import nose
     nose.runmodule(argv=['-s', '--with-doctest'], exit=False)
diff --git a/lib/cartopy/tests/mpl/test_gridliner.py b/lib/cartopy/tests/mpl/test_gridliner.py
--- a/lib/cartopy/tests/mpl/test_gridliner.py
+++ b/lib/cartopy/tests/mpl/test_gridliner.py
@@ -17,9 +17,6 @@
 
 from __future__ import (absolute_import, division, print_function)
 
-import unittest
-import warnings
-
 from matplotlib.backends.backend_agg import FigureCanvasAgg
 import matplotlib.pyplot as plt
 import matplotlib.ticker as mticker