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

FIX: Remove force_path_ccw of contours #2298

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Conversation

greglucas
Copy link
Contributor

This was added to fix previously unoriented paths from Matplotlib's contouring code. This has seemingly been fixed upstream somewhere in the past and there is no test/reproducer in Cartopy, so we can remove this for now because the polygons are oriented as Shapely expects from Matplotlib.

closes #2288

If anyone has ideas for good test cases, it would be nice to add some, but I haven't really given much thought to what produces the bad geometries. An example of what I think would be nice to test below with some minimal values.

  1. Contour with a hole in middle of projection
  2. Contour with a hole wrapped around the edge of the globe (set central_longitude=180 in the proj_map call)
  3. Others...?
import numpy as np
import matplotlib.pyplot as plt
from cartopy import crs as ccrs


proj_data = ccrs.PlateCarree()
proj_map = ccrs.Robinson()

xx, yy = np.meshgrid([-20, 0, 20], [-20, 0, 20])
levels = (10, 50)
zz = np.abs(xx) + np.abs(yy)

ax = plt.figure().add_subplot(projection=proj_map)

cset = ax.contourf(xx, yy, zz, transform=proj_data, levels=levels)
ax.coastlines()

plt.show()

Copy link
Member

@rcomer rcomer left a comment

Choose a reason for hiding this comment

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

I don't know how you begin to write a test for this given that we do not have the data from the original issue. I think it makes sense to remove these line as we have no evidence they are still needed.

However, I think there is more going on with #2288: noting that the latitudes in the example run north-south (which I assume is why the contours end up clockwise), if we flip the latitude direction we can still reproduce the problem plot regardless of whether we use main or this branch.

This was added to fix previously unoriented paths from Matplotlib's
contouring code. This has seemingly been fixed upstream somewhere
in the past and there is no test/reproducer in Cartopy, so we
can remove this for now.
@greglucas
Copy link
Contributor Author

I think that is a separate issue/bug then having to do with the wrapping of polygons probably... If we flip the indices in that example to be sorted -180 -> 180 (like we do in the transform_first path) then there is no yellow polygon filling everything.

ind = np.argsort(x, axis=1)
x = np.take_along_axis(x, ind, axis=1)
y = np.take_along_axis(y, ind, axis=1)
v = np.take_along_axis(v, ind, axis=1)

@greglucas
Copy link
Contributor Author

Here is a good issue with links to others all with some geometry getting wrapped around boundaries incorrectly: #2137
which might have the same effect as what is happening here.

@rcomer
Copy link
Member

rcomer commented Dec 18, 2023

Let's get this in anyway...

@rcomer rcomer merged commit 879f84f into SciTools:main Dec 18, 2023
22 checks passed
@greglucas greglucas deleted the force-ccw-fix branch December 18, 2023 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cartopy 0.22 + matplotlib 3.8 + contourf bug?
3 participants