I updated matplotlib, shapely and cartopy to their latest versions and now it works.
matplotlib: 3.10.5 shapely: 2.1.1 cartopy: 0.24.1