diff --git a/src/pyflexplot/plotting/boxed_plot.py b/src/pyflexplot/plotting/boxed_plot.py index 1bec7e9a..4ea38f8b 100644 --- a/src/pyflexplot/plotting/boxed_plot.py +++ b/src/pyflexplot/plotting/boxed_plot.py @@ -18,6 +18,7 @@ import numpy as np from matplotlib import pyplot as plt from matplotlib.figure import Figure +import warnings # Local from ..input.field import Field @@ -319,9 +320,10 @@ def _draw_colors_contours( # Replace infs (apparently ignored by contourf) arr = np.where(np.isneginf(arr), np.finfo(np.float32).min, arr) arr = np.where(np.isposinf(arr), np.finfo(np.float32).max, arr) + before = list(ax.ax.collections) try: - contours = ax.ax.contourf( + ax.ax.contourf( field.lon, field.lat, arr, @@ -337,9 +339,21 @@ def _draw_colors_contours( # (Easier to catch error than explicitly detect 'empty' array) return raise e - else: - for contour in contours.collections: - contour.set_rasterized(True) + + new = ax.ax.collections[len(before):] + for coll in new: + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + coll.set_rasterized(True) + + # if this coll doesn't support being rasterized, ignore + if any( + issubclass(wi.category, UserWarning) + and "Rasterization of" in str(wi.message) + and "will be ignored" in str(wi.message) + for wi in w + ): + continue def _add_markers(ax: MapAxes, field: Field, markers_config: MarkersConfig) -> None: