Skip to content
Open
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
22 changes: 18 additions & 4 deletions src/pyflexplot/plotting/boxed_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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):]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new = ax.ax.collections[len(before):]
# Workaround for deprecated contours.collection:
# Loop over ax.collections, ignore warning that are produced for collections
# that cannot be rasterized.
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:
Expand Down