Skip to content

Commit

Permalink
Use transform_first=True for contourf plots with Robinson projectio…
Browse files Browse the repository at this point in the history
…n to avoid cartopy bug (#3789)
  • Loading branch information
schlunma authored Oct 30, 2024
1 parent f18fe9c commit 0961c45
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion esmvaltool/cmorizers/data/formatters/datasets/cmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
from pathlib import Path

import iris
from esmvaltool.cmorizers.data import utilities as utils

from esmvaltool.cmorizers.data import utilities as utils

logger = logging.getLogger(__name__)

Expand Down
9 changes: 9 additions & 0 deletions esmvaltool/diag_scripts/monitor/multi_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,9 @@ def _plot_map_with_ref(self, plot_func, dataset, ref_dataset):
axes_data = fig.add_subplot(gridspec[0:2, 0:2],
projection=projection)
plot_kwargs['axes'] = axes_data
if plot_func is iris.plot.contourf:
# see https://github.com/SciTools/cartopy/issues/2457
plot_kwargs['transform_first'] = True
plot_data = plot_func(cube, **plot_kwargs)
axes_data.coastlines()
if gridline_kwargs is not False:
Expand Down Expand Up @@ -1212,6 +1215,9 @@ def _plot_map_with_ref(self, plot_func, dataset, ref_dataset):
plot_kwargs_bias = self._get_plot_kwargs(plot_type, dataset,
bias=True)
plot_kwargs_bias['axes'] = axes_bias
if plot_func is iris.plot.contourf:
# see https://github.com/SciTools/cartopy/issues/2457
plot_kwargs_bias['transform_first'] = True
plot_bias = plot_func(bias_cube, **plot_kwargs_bias)
axes_bias.coastlines()
if gridline_kwargs is not False:
Expand Down Expand Up @@ -1268,6 +1274,9 @@ def _plot_map_without_ref(self, plot_func, dataset):
axes = fig.add_subplot(projection=self._get_map_projection())
plot_kwargs = self._get_plot_kwargs(plot_type, dataset)
plot_kwargs['axes'] = axes
if plot_func is iris.plot.contourf:
# see https://github.com/SciTools/cartopy/issues/2457
plot_kwargs['transform_first'] = True
plot_map = plot_func(cube, **plot_kwargs)
axes.coastlines()
gridline_kwargs = self._get_gridline_kwargs(plot_type)
Expand Down
1 change: 1 addition & 0 deletions esmvaltool/diag_scripts/shared/plot/_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def global_contourf(cube,
if cbar_range is not None:
levels = np.linspace(*cbar_range)
kwargs['levels'] = levels
kwargs['transform_first'] = True # see SciTools/cartopy/issues/2457
axes = plt.axes(projection=ccrs.Robinson(central_longitude=10))
plt.sca(axes)
map_plot = iris.plot.contourf(cube, **kwargs)
Expand Down

0 comments on commit 0961c45

Please sign in to comment.