From 36f0fc571c2bd7aef85f8e45d35bbf340317dc55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peider=20K=C3=B6nz?= Date: Fri, 9 Jan 2026 16:44:10 +0100 Subject: [PATCH 1/2] Dirty solution to issue 70 --- src/pyflexplot/plotting/boxed_plot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pyflexplot/plotting/boxed_plot.py b/src/pyflexplot/plotting/boxed_plot.py index 1bec7e9a..309fee92 100644 --- a/src/pyflexplot/plotting/boxed_plot.py +++ b/src/pyflexplot/plotting/boxed_plot.py @@ -338,8 +338,8 @@ def _draw_colors_contours( return raise e else: - for contour in contours.collections: - contour.set_rasterized(True) + for child in contours.get_children(): + child.set_rasterized(True) def _add_markers(ax: MapAxes, field: Field, markers_config: MarkersConfig) -> None: From acb4cd0414a1983e67b431e07ebb6c8b17d65dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peider=20K=C3=B6nz?= Date: Mon, 12 Jan 2026 15:44:01 +0100 Subject: [PATCH 2/2] better solution --- src/pyflexplot/plotting/boxed_plot.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/pyflexplot/plotting/boxed_plot.py b/src/pyflexplot/plotting/boxed_plot.py index 309fee92..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 child in contours.get_children(): - child.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: