cartopy
cartopy copied to clipboard
tricontour and tricontourf produce wrong bounds
Description
Similar to issue #811 and its fix #814, tricontour and tricountourf incorrectly Change the bounds of the plot to be extremely zoomed in. i.e.:

The extent can be reset using:
ax.relim()
ax.autoscale_view()

Code to reproduce
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
import cartopy.crs as ccrs
npts = 5000
latCell = np.random.uniform(-90.0, 90.0, npts)
lonCell = np.random.uniform(-180.0, 180.0, npts)
data = np.random.random_sample((latCell.shape[0]))
bmap = ccrs.Orthographic()
ax = plt.axes(projection=bmap)
ax.coastlines()
ax.gridlines()
plt.tricontourf(lonCell,
latCell,
data,
75,
vmin=data.min(),
vmax=data.max(),
transform=ccrs.PlateCarree())
#ax.relim()
#ax.autoscale_view()
Similar open issues include #1301, #1302 and maybe #1293(?). We definitely have some interest in getting tricontour and tricontourf working correctly for plotting MPAS field. I definitely have an interesting in helping make this contribution, but I'll need to get permission from NCAR and I would most likely need some help making the change as well.
Full environment definition
Operating system
SUSE Linux Enterprise Server 12 SP4
Cartopy version
0.17.0
conda list
Not using conda
pip list
Package Version Location
----------------------------- ---------- --------------------------------
alabaster 0.7.12
ASAPTools 0.6.2
asn1crypto 0.24.0
aspy.yaml 1.3.0
astroid 2.2.5
atomicwrites 1.3.0
attrs 19.1.0
Babel 2.7.0
backcall 0.1.0
basemap 1.2.0
bash-kernel 0.7.1
beautifulsoup4 4.7.1
bitstring 3.1.5
bleach 3.1.0
boto3 1.9.179
botocore 1.12.179
Bottleneck 1.2.1
Cartopy 0.17.0
cdsapi 0.1.4
certifi 2019.6.16
cf-units 2.0.2
cffi 1.12.3
cfgv 2.0.0
cftime 1.0.3.4
chardet 3.0.4
click 6.7
click-plugins 1.1.1
cligj 0.5.0
cloudpickle 1.2.1
cmocean 2.0
colorspacious 1.1.2
configobj 5.0.6
coverage 4.5.3
cryptography 2.5
cycler 0.10.0
Cython 0.29.10
dask 2.0.0
dask-jobqueue 0.5.0
decorator 4.4.0
dedalus 2.1810
defusedxml 0.6.0
distributed 2.0.1
docopt 0.6.2
docrep 0.2.7
docutils 0.14
entrypoints 0.3
ESMPy 7.1.0.dev0
Fiona 1.8.4
GDAL 2.4.0
geopandas 0.5.0
gfstonc 0.0.1
globus-cli 1.10.1
globus-sdk 1.7.1
h5py 2.9.0
HeapDict 1.0.0
html5lib 1.0.1
httplib2 0.13.0
icc-rt 2019.0
identify 1.4.5
idl-python 2.0
idna 2.8
imageio 2.5.0
imagesize 1.1.0
importlib-metadata 0.18
importlib-resources 1.0.2
intel-openmp 2019.0
ipykernel 5.1.1
ipyparallel 6.2.4
ipython 7.5.0
ipython-genutils 0.2.0
ipywidgets 7.4.2
isort 4.3.21
jedi 0.14.0
Jinja2 2.10.1
jmespath 0.9.2
joblib 0.13.2
jsonschema 3.0.1
jupyter 1.0.0
jupyter-client 5.2.4
jupyter-console 6.0.0
jupyter-core 4.5.0
jupyterlab 0.35.6
jupyterlab-server 0.2.0
kiwisolver 1.1.0
lazy-object-proxy 1.4.1
llvmlite 0.27.0
MarkupSafe 1.1.1
matlab-kernel 0.16.7
matlabengineforpython R2018a
matplotlib 2.2.3
mccabe 0.6.1
metakernel 0.24.2
MetPy 0.10.0
mistune 0.8.4
mkl 2019.0
mkl-fft 1.0.6
mkl-random 1.0.1.1
more-itertools 7.1.0
MPAS-Limited-Area 0.1
mpi4py 3.0.0
msgpack 0.6.1
munch 2.3.2
natgrid 0.2.1
nbconvert 5.5.0
nbformat 4.4.0
netCDF4 1.5.1.2
networkx 2.3
ngl 1.6.1
nodeenv 1.3.3
nose 1.3.7
nose2 0.9.1
notebook 5.7.8
numba 0.42.0
numexpr 2.6.9
numpy 1.15.4
ocgis 2.1.1
olefile 0.46
packaging 19.0
pandas 0.24.2
pandocfilters 1.4.2
parse 1.12.0
parso 0.5.0
pexpect 4.7.0
pickleshare 0.7.5
Pillow 6.0.0
Pint 0.9
pip 19.1.1
pluggy 0.12.0
pooch 0.2.1
pre-commit 1.17.0
prettytable 0.7.2
progressbar2 3.42.0
prometheus-client 0.7.1
prompt-toolkit 2.0.9
protobuf 3.9.0rc1
psutil 5.6.3
ptyprocess 0.6.0
py 1.8.0
pybufrkit 0.2.7
pycparser 2.19
Pydap 3.2.2
Pygments 2.4.2
pygraphviz 1.5
pygrib 2.0.3
pyhdf 0.9.0
PyJWT 1.7.1
pylint 2.3.1
PyNIO 1.5.5
pyparsing 2.4.0
pyproj 1.9.6
pyrsistent 0.15.2
pyshp 2.1.0
pyspharm 1.0.8
pytest 4.6.3
python-dateutil 2.8.0
python-utils 2.3.0
pytz 2019.1
PyWavelets 1.0.3
PyYAML 5.1.1
pyzmq 18.0.2
qtconsole 4.5.1
regionmask 0.4.0
requests 2.22.0
rise 5.5.0
s3transfer 0.2.1
scikit-image 0.15.0
scikit-learn 0.21.2
scipy 1.3.0
seaborn 0.9.0
Send2Trash 1.5.0
setuptools 41.0.1
sh 1.12.14
Shapely 1.7a1
SHTns 3.1
sip 4.19.13
siphon 0.8.0
six 1.12.0
SkewT 1.1.0
sklearn-xarray 0.3.0
snowballstemmer 1.9.0
sortedcontainers 2.1.0
soupsieve 1.9.2
Sphinx 2.1.2
sphinxcontrib-applehelp 1.0.1
sphinxcontrib-devhelp 1.0.1
sphinxcontrib-htmlhelp 1.0.2
sphinxcontrib-jsmath 1.0.1
sphinxcontrib-qthelp 1.0.2
sphinxcontrib-serializinghtml 1.1.3
tables 3.4.4
tbb 2019.0
tbb4py 2019.0
tblib 1.4.0
terminado 0.8.2
testpath 0.4.2
toml 0.10.0
toolz 0.9.0
tornado 6.0.3
traitlets 4.3.2
typed-ast 1.4.0
urllib3 1.25.3
virtualenv 16.6.1
virtualenv-clone 0.5.3
viscm 0.8
wcwidth 0.1.7
webencodings 0.5.1
WebOb 1.8.5
wheel 0.33.4
widgetsnbextension 3.4.2
wrapt 1.11.2
wrf-python 1.3.0
wurlitzer 1.0.3
xarray 0.12.1
xesmf 0.1.1
xlrd 1.2.0
zict 1.0.0
zipp 0.5.1
I also noticed this bug when applying a collection of patches to an axes:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.collections as mplcollections
from matplotlib.patches import Circle
import cartopy.crs as ccrs
colors = np.linspace(0, 1, num=4)
bmap = ccrs.Orthographic(central_longitude=-100)
ax = plt.axes(projection=bmap)
ax.coastlines()
ax.gridlines()
patches = []
patches.append(Circle((-90, -45), radius=30))
patches.append(Circle((-90, 45), radius=30))
collection = mplcollections.PatchCollection(patches,
transform=ccrs.PlateCarree())
collection.set_array(colors)
ax.add_collection(collection)
#ax.relim()
#ax.autoscale_view()

And then after ax.relim() and ax.autoscale_view():

Perhaps there is a better method for doing this in Cartopy that I am not aware of?
@MiCurry any development on this one?
This is due to the extent of the axes not being initialized immediately to your coordinate frame. If you add ax.set_global() right after your axis creation this works as you expect I think.
ax = plt.axes(projection=bmap)
ax.set_global()
See PR #1370 for an attempt to clear up this common confusion.
@koldunovn It appears so! Thanks for the information and the PR on this @greglucas.