Contouring with cartopy: ValueError: invalid transform: Spherical contouring is not supported

StackOverflow https://stackoverflow.com/questions/13657748

  •  04-12-2021
  •  | 
  •  

Question

I'd like to plot contours over a map produced with cartopy. If I run the example at:

http://scitools.org.uk/cartopy/docs/latest/matplotlib/introductory_examples/03.contours.html

using a checkout of the latest code from github I get:

ValueError: invalid transform: Spherical contouring is not supported -  
consider using PlateCarree/RotatedPole.

How should one do this?

(asked as a response to the original announcement http://matplotlib.1069221.n5.nabble.com/ANN-Cartopy-A-new-mapping-library-using-matplotlib-td39886.html)

Was it helpful?

Solution

The examples provided in the cartopy docs under http://scitools.org.uk/cartopy/docs/latest/matplotlib/introductory_examples are out of date compared to the codebase. There is a development ticket to update all of the examples (https://github.com/SciTools/cartopy/issues/128).

In this case, simply replace the line

plt.contourf(lons, lats, data, transform=ccrs.Geodetic())

with

plt.contourf(lons, lats, data, transform=ccrs.PlateCarree())

and the example should work again.

The matplotlib/cartopy introductory section of the cartopy docs has has a contouring example which may be of interest http://scitools.org.uk/cartopy/docs/latest/matplotlib/advanced_plotting.html#contour-plots The resulting image:

output from linked example

HTH,

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top