cartopy icon indicating copy to clipboard operation
cartopy copied to clipboard

Contourf plot with Robinson projection produces wrong results dependent on `central_longitude`

Open schlunma opened this issue 1 year ago • 1 comments

Description

Using contourf produces wrong plots with the Robinson projection depending on the setting of central_longitude.

Code to reproduce

import iris
import iris.plot
import matplotlib.pyplot as plt
import cartopy.crs as ccrs

cube = iris.load_cube(path)

fig = plt.figure()
projection = ccrs.Robinson(central_longitude=0.0)
axes = fig.add_subplot(projection=projection)
axes.contourf(cube.coord('longitude').points, cube.coord('latitude').points, cube.data, cmap='bwr', levels=12, transform=ccrs.PlateCarree())

With this dataset, this produces the wrong

grafik

With this dataset, this produces the correct

grafik

Note that these plots should look very different. The extensions .txt need to be removed for the files.

Changing to central_longitude=10.0 in the code example swaps this behavior: the first example now looks fine and the second one looks weird. This also seem to depend on the number of levels.

Using pcolormesh creates nicely looking plots in all cases.

Full environment definition

Operating system

Cartopy version

0.23.0

conda list

env.txt

pip list

pip.txt

schlunma avatar Oct 22 '24 16:10 schlunma

Thanks @schlunma, unfortunately this is a long-standing known problem, and hard to track down. One possible work-around is to use the transform_first option, which should also make it plot faster. https://scitools.org.uk/cartopy/docs/latest/gallery/scalar_data/contour_transforms.html

rcomer avatar Oct 23 '24 09:10 rcomer