Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use transform_first=True for contourf plots with Robinson projection to avoid cartopy bug #3789

Merged
merged 3 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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