Repository: SciTools/cartopy

Issue:
SlippyImageArtist is broken with tight layout
### Description
<!-- Please provide a general introduction to the issue/proposal. -->
Cartopy generates the following error when attempting to use plt.show() to visualize a map within Pycharm/Spyder: 
TypeError: cannot unpack non-iterable NoneType object

If plt.show() is not used or is commented out, the figure can be saved to a file and is plotted correctly.
<!--
If you are reporting a bug, attach the *entire* traceback from Python.

If you are proposing an enhancement/new feature, provide links to related articles, reference examples, etc.

If you are asking a question, please ask on StackOverflow and use the cartopy tag. All cartopy
questions on StackOverflow can be found at https://stackoverflow.com/questions/tagged/cartopy
-->

#### Code to reproduce

```
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import cartopy.feature as cfeature
import os

fig = plt.figure(figsize=[10, 10])
projection = ccrs.Mercator()
ax = plt.axes(projection=projection)
geodetic = ccrs.Geodetic(globe=ccrs.Globe(datum='WGS84'))
ax.set_extent([-114.5, -110.0, 36.75, 40.25])

url = 'https://map1.vis.earthdata.nasa.gov/wmts-geo/wmts.cgi'
layer = 'Landsat_WELD_CorrectedReflectance_TrueColor_Global_Annual'
ax.add_wmts(wmts=url, layer_name=layer, alpha=0.8)
plt.show()
```

#### Traceback 

```
Traceback (most recent call last):
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/IPython/core/interactiveshell.py", line 3319, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-8-7607f9c8266c>", line 59, in <module>
    plt.show()
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/matplotlib/pyplot.py", line 269, in show
    return _show(*args, **kw)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 27, in __call__
    manager.show(**kwargs)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 99, in show
    self.canvas.show()
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 64, in show
    self.figure.tight_layout()
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/matplotlib/figure.py", line 2476, in tight_layout
    pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/matplotlib/tight_layout.py", line 362, in get_tight_layout_figure
    pad=pad, h_pad=h_pad, w_pad=w_pad)
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/matplotlib/tight_layout.py", line 111, in auto_adjust_subplotpars
    tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/matplotlib/tight_layout.py", line 112, in <listcomp>
    if ax.get_visible()])
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 4393, in get_tightbbox
    bbox = a.get_tightbbox(renderer)
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/matplotlib/artist.py", line 284, in get_tightbbox
    bbox = self.get_window_extent(renderer)
  File "/home/dwells/anaconda3/envs/kando/lib/python3.7/site-packages/matplotlib/image.py", line 868, in get_window_extent
    x0, x1, y0, y1 = self._extent
TypeError: cannot unpack non-iterable NoneType object
```

<details>
 <summary>Full environment definition</summary>


<!-- fill in the following information as appropriate -->

### Operating system
macOS high sierra
10.13.6

### Cartopy version
0.17.0

### conda list

```
# packages in environment at /home/dwells/anaconda3/envs/kando:
#
# Name                    Version                   Build  Channel
_tflow_select             2.3.0                       mkl  
absl-py                   0.8.1                    py37_0  
alabaster                 0.7.12                   py37_0  
applaunchservices         0.2.1                      py_0  
appnope                   0.1.0                    py37_0  
argh                      0.26.2                   py37_0  
asn1crypto                1.3.0                    py37_0  
astor                     0.8.0                    py37_0  
astroid                   2.3.3                    py37_0  
atomicwrites              1.3.0                    py37_1  
attrs                     19.3.0                     py_0  
autopep8                  1.4.4                      py_0  
babel                     2.8.0                      py_0  
backcall                  0.1.0                    py37_0  
basemap                   1.2.0            py37h0acbc05_0  
blas                      1.0                         mkl  
bleach                    3.1.0                    py37_0  
c-ares                    1.15.0            h1de35cc_1001  
ca-certificates           2019.11.28           hecc5488_0    conda-forge
cartopy                   0.17.0          py37h707127b_1000    conda-forge
certifi                   2019.11.28               py37_0    conda-forge
cffi                      1.13.2           py37hb5b8e2f_0  
chardet                   3.0.4                 py37_1003  
cloudpickle               1.2.2                      py_0  
cryptography              2.8              py37ha12b0ac_0  
cycler                    0.10.0                   py37_0  
dbus                      1.13.12              h90a0687_0  
decorator                 4.4.1                      py_0  
defusedxml                0.6.0                      py_0  
diff-match-patch          20181111                   py_0  
docutils                  0.15.2                   py37_0  
entrypoints               0.3                      py37_0  
expat                     2.2.6                h0a44026_0  
flake8                    3.7.9                    py37_0  
freetype                  2.9.1                hb4e5f40_0  
future                    0.18.2                   py37_0  
gast                      0.3.2                      py_0  
geographiclib             1.50                       py_0    conda-forge
geopy                     1.20.0                     py_0    conda-forge
geos                      3.6.2             h0a44026_1004    conda-forge
gettext                   0.19.8.1             h15daf44_3  
glib                      2.63.1               hd977a24_0  
grpcio                    1.16.1           py37h044775b_1  
h5py                      2.9.0            py37h3134771_0  
hdf5                      1.10.4               hfa1e0ec_0  
icu                       58.2                 h4b95b61_1  
idna                      2.8                      py37_0  
imagesize                 1.2.0                      py_0  
importlib_metadata        1.3.0                    py37_0  
intel-openmp              2019.4                      233  
intervaltree              3.0.2                      py_0  
ipykernel                 5.1.3            py37h39e3cac_1  
ipython                   7.11.1           py37h39e3cac_0  
ipython_genutils          0.2.0                    py37_0  
isort                     4.3.21                   py37_0  
jedi                      0.14.1                   py37_0  
jinja2                    2.10.3                     py_0  
joblib                    0.14.1                     py_0  
jpeg                      9b                   he5867d9_2  
jsonschema                3.2.0                    py37_0  
jupyter_client            5.3.4                    py37_0  
jupyter_core              4.6.1                    py37_0  
keras                     2.2.4                         0  
keras-applications        1.0.8                      py_0  
keras-base                2.2.4                    py37_0  
keras-preprocessing       1.1.0                      py_1  
keyring                   20.0.0                   py37_0  
kiwisolver                1.1.0            py37h0a44026_0  
lazy-object-proxy         1.4.3            py37h1de35cc_0  
libcxx                    4.0.1                hcfea43d_1  
libcxxabi                 4.0.1                hcfea43d_1  
libedit                   3.1.20181209         hb402a30_0  
libffi                    3.2.1                h475c297_4  
libgfortran               3.0.1                h93005f0_2  
libiconv                  1.15                 hdd342a3_7  
libpng                    1.6.37               ha441bb4_0  
libprotobuf               3.11.2               hd9629dc_0  
libsodium                 1.0.16               h3efe00b_0  
libspatialindex           1.9.3                h0a44026_0  
libtiff                   4.0.9                he6b73bb_1    conda-forge
libxml2                   2.9.9                hd80cff7_2    conda-forge
libxslt                   1.1.32            h1e79283_1003    conda-forge
llvm-openmp               4.0.1                hcfea43d_1  
lxml                      4.4.1            py37h08abf6f_0    conda-forge
markdown                  3.1.1                    py37_0  
markupsafe                1.1.1            py37h1de35cc_0  
matplotlib                3.1.1            py37h54f8f79_0  
matplotlib-base           3.1.1            py37h3a684a6_1    conda-forge
mccabe                    0.6.1                    py37_1  
mistune                   0.8.4            py37h1de35cc_0  
mkl                       2019.4                      233  
mkl-service               2.3.0            py37hfbe908c_0  
mkl_fft                   1.0.15           py37h5e564d8_0  
mkl_random                1.1.0            py37ha771720_0  
more-itertools            8.0.2                      py_0  
nbconvert                 5.6.1                    py37_0  
nbformat                  4.4.0                    py37_0  
ncurses                   6.1                  h0a44026_1  
numpy                     1.15.4           py37hacdab7b_0  
numpy-base                1.15.4           py37h6575580_0  
numpydoc                  0.9.2                      py_0  
obspy                     1.1.1            py37h917ab60_1    conda-forge
olefile                   0.46                       py_0    conda-forge
openssl                   1.1.1d               h0b31af3_0    conda-forge
owslib                    0.19.1                     py_0    conda-forge
packaging                 20.0                       py_0  
pandas                    0.25.3           py37h0a44026_0  
pandoc                    2.2.3.2                       0  
pandocfilters             1.4.2                    py37_1  
parso                     0.5.2                      py_0  
pathtools                 0.1.2                      py_1  
pcre                      8.43                 h0a44026_0  
pexpect                   4.7.0                    py37_0  
pickleshare               0.7.5                    py37_0  
pillow                    5.4.1            py37hb68e598_0  
pip                       19.3.1                   py37_0  
pluggy                    0.13.1                   py37_0  
proj4                     4.9.3                h01d97ff_9    conda-forge
prompt_toolkit            3.0.2                      py_0  
protobuf                  3.11.2           py37h0a44026_0  
psutil                    5.6.7            py37h1de35cc_0  
ptyprocess                0.6.0                    py37_0  
pycodestyle               2.5.0                    py37_0  
pycparser                 2.19                     py37_0  
pydocstyle                4.0.1                      py_0  
pyepsg                    0.4.0                      py_0    conda-forge
pyflakes                  2.1.1                    py37_0  
pygments                  2.5.2                      py_0  
pykdtree                  1.3.1           py37h3b54f70_1002    conda-forge
pylint                    2.4.4                    py37_0  
pyopenssl                 19.1.0                   py37_0  
pyparsing                 2.4.6                      py_0  
pyproj                    1.9.5.1         py37hfb6cdf6_1006    conda-forge
pyqt                      5.9.2            py37h655552a_2  
pyrsistent                0.15.6           py37h1de35cc_0  
pyshp                     2.1.0                      py_0    conda-forge
pysocks                   1.7.1                    py37_0  
python                    3.7.6                h359304d_2  
python-dateutil           2.8.1                      py_0  
python-jsonrpc-server     0.3.2                      py_0  
python-language-server    0.31.2                   py37_0  
python.app                2                        py37_9  
pytz                      2019.3                     py_0  
pyyaml                    5.2              py37h1de35cc_0  
pyzmq                     18.1.0           py37h0a44026_0  
qdarkstyle                2.7                        py_0  
qt                        5.9.7                h468cd18_1  
qtawesome                 0.6.0                      py_0  
qtconsole                 4.6.0                      py_1  
qtpy                      1.9.0                      py_0  
readline                  7.0                  h1de35cc_5  
requests                  2.22.0                   py37_1  
rope                      0.14.0                     py_0  
rtree                     0.8.3                    py37_0  
scikit-learn              0.22.1           py37h27c97d8_0  
scipy                     1.3.1            py37h1410ff5_0  
setuptools                44.0.0                   py37_0  
shapely                   1.6.4           py37h2e8a847_1000    conda-forge
sip                       4.19.8           py37h0a44026_0  
six                       1.13.0                   py37_0  
snowballstemmer           2.0.0                      py_0  
sortedcontainers          2.1.0                    py37_0  
sphinx                    2.3.1                      py_0  
sphinxcontrib-applehelp   1.0.1                      py_0  
sphinxcontrib-devhelp     1.0.1                      py_0  
sphinxcontrib-htmlhelp    1.0.2                      py_0  
sphinxcontrib-jsmath      1.0.1                      py_0  
sphinxcontrib-qthelp      1.0.2                      py_0  
sphinxcontrib-serializinghtml 1.1.3                      py_0  
spyder                    4.0.1                    py37_0  
spyder-kernels            1.8.1                    py37_0  
sqlalchemy                1.3.12           py37h0b31af3_0    conda-forge
sqlite                    3.30.1               ha441bb4_0  
tensorboard               1.14.0           py37h80053f4_0  
tensorflow                1.14.0          mkl_py37h085be34_0  
tensorflow-base           1.14.0          mkl_py37h5a24fda_0  
tensorflow-estimator      1.14.0                     py_0  
termcolor                 1.1.0                    py37_1  
testpath                  0.4.4                      py_0  
tk                        8.6.8                ha441bb4_0  
tornado                   6.0.3            py37h1de35cc_0  
traitlets                 4.3.3                    py37_0  
ujson                     1.35             py37h1de35cc_0  
urllib3                   1.25.7                   py37_0  
watchdog                  0.9.0                    py37_1  
wcwidth                   0.1.7                    py37_0  
webencodings              0.5.1                    py37_1  
werkzeug                  0.16.0                     py_0  
wheel                     0.33.6                   py37_0  
wrapt                     1.11.2           py37h1de35cc_0  
wurlitzer                 2.0.0                    py37_0  
xz                        5.2.4                h1de35cc_4  
yaml                      0.1.7                hc338f04_2  
yapf                      0.28.0                     py_0  
zeromq                    4.3.1                h0a44026_3  
zipp                      0.6.0                      py_0  
zlib                      1.2.11               h1de35cc_3
```

### pip list

```
```

</details>



Discussion:
>   File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pycharm_matplotlib_backend/backend_interagg.py", line 64, in show
>     self.figure.tight_layout()

This is because PyCharn calls tight layout. If you can configure it to not do that, that plot would work.

This can be reproduced without PyCharm by adding `fig.tight_layout()` before `plt.show()`.
```pytb
  File "issue1451.py", line 13, in <module>
    fig.tight_layout()
  File "python3.6/site-packages/matplotlib/figure.py", line 2476, in tight_layout
    pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
  File "python3.6/site-packages/matplotlib/tight_layout.py", line 362, in get_tight_layout_figure
    pad=pad, h_pad=h_pad, w_pad=w_pad)
  File "python3.6/site-packages/matplotlib/tight_layout.py", line 111, in auto_adjust_subplotpars
    tight_bbox_raw = union([ax.get_tightbbox(renderer) for ax in subplots
  File "python3.6/site-packages/matplotlib/tight_layout.py", line 112, in <listcomp>
    if ax.get_visible()])
  File "python3.6/site-packages/matplotlib/axes/_base.py", line 4393, in get_tightbbox
    bbox = a.get_tightbbox(renderer)
  File "python3.6/site-packages/matplotlib/artist.py", line 284, in get_tightbbox
    bbox = self.get_window_extent(renderer)
  File "python3.6/site-packages/matplotlib/image.py", line 868, in get_window_extent
    x0, x1, y0, y1 = self._extent
```

Resolving patch:
diff --git a/lib/cartopy/mpl/slippy_image_artist.py b/lib/cartopy/mpl/slippy_image_artist.py
--- a/lib/cartopy/mpl/slippy_image_artist.py
+++ b/lib/cartopy/mpl/slippy_image_artist.py
@@ -39,6 +39,9 @@ class SlippyImageArtist(AxesImage):
     """
     def __init__(self, ax, raster_source, **kwargs):
         self.raster_source = raster_source
+        if matplotlib.__version__ >= '3':
+            # This artist fills the Axes, so should not influence layout.
+            kwargs.setdefault('in_layout', False)
         super(SlippyImageArtist, self).__init__(ax, **kwargs)
         self.cache = []
 
@@ -54,6 +57,9 @@ def on_release(self, event=None):
         self.user_is_interacting = False
         self.stale = True
 
+    def get_window_extent(self, renderer=None):
+        return self.axes.get_window_extent(renderer=renderer)
+
     @matplotlib.artist.allow_rasterization
     def draw(self, renderer, *args, **kwargs):
         if not self.get_visible():


Test patch:
diff --git a/lib/cartopy/tests/mpl/test_web_services.py b/lib/cartopy/tests/mpl/test_web_services.py
--- a/lib/cartopy/tests/mpl/test_web_services.py
+++ b/lib/cartopy/tests/mpl/test_web_services.py
@@ -18,6 +18,7 @@
 from __future__ import (absolute_import, division, print_function)
 
 import matplotlib.pyplot as plt
+from matplotlib.testing.decorators import cleanup
 import pytest
 
 from cartopy.tests.mpl import MPL_VERSION, ImageTesting
@@ -36,6 +37,17 @@ def test_wmts():
     ax.add_wmts(url, 'MODIS_Water_Mask')
 
 
+@pytest.mark.network
+@pytest.mark.skipif(not _OWSLIB_AVAILABLE, reason='OWSLib is unavailable.')
+@cleanup
+def test_wms_tight_layout():
+    ax = plt.axes(projection=ccrs.PlateCarree())
+    url = 'http://vmap0.tiles.osgeo.org/wms/vmap0'
+    layer = 'basic'
+    ax.add_wms(url, layer)
+    ax.figure.tight_layout()
+
+
 @pytest.mark.network
 @pytest.mark.xfail((5, 0, 0) <= ccrs.PROJ4_VERSION < (5, 1, 0),
                    reason='Proj Orthographic projection is buggy.',