Skip to content

Commit

Permalink
Use boundary to compute axes domain in gridliner
Browse files Browse the repository at this point in the history
Fix SciTools#1443

Merge the old and the new algo for the axes domain estimate

The coordinates of the outline are simply added to the rasterised coordinates.

In addition, the rasterized coordinates are generated with a non-even number of ticks to make sure to catch the center when bounds are symetric.

Add gridliner_orthographic test

This tests Gridliner._axes_domain

Update figs due to new gridliner axes domain

Fix figure testing for crs

Fix tolerance for test_gridliner

Remove unneeded call to ravel
  • Loading branch information
stefraynaud committed Apr 16, 2021
1 parent 4ca93c1 commit da219bc
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 4 deletions.
11 changes: 8 additions & 3 deletions lib/cartopy/mpl/gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,13 +852,18 @@ def _axes_domain(self, nx=None, ny=None):
ax_transform = self.axes.transAxes
desired_trans = ax_transform - transform

nx = nx or 100
ny = ny or 100
nx = nx or 101
ny = ny or 101
x = np.linspace(1e-9, 1 - 1e-9, nx)
y = np.linspace(1e-9, 1 - 1e-9, ny)
x, y = np.meshgrid(x, y)

coords = np.column_stack((x.ravel(), y.ravel()))
xyp = (self.axes.patch.get_transform()-ax_transform).transform(
self.axes.patch.get_path().vertices)
x = np.concatenate((x.ravel(), xyp[:, 0]))
y = np.concatenate((y.ravel(), xyp[:, 1]))

coords = np.column_stack((x, y))

in_data = desired_trans.transform(coords)

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion lib/cartopy/tests/mpl/test_gridliner.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
@pytest.mark.natural_earth
@ImageTesting(['gridliner1'],
# Robinson projection is slightly better in Proj 6+.
tolerance=0.7 if ccrs.PROJ4_VERSION >= (6, 0, 0) else 0.5)
tolerance=0.7 if ccrs.PROJ4_VERSION >= (6, 0, 0) else 0.62)
def test_gridliner():
ny, nx = 2, 4

Expand Down Expand Up @@ -112,6 +112,13 @@ def test_gridliner():
top=1 - delta, bottom=0 + delta)


@ImageTesting(['gridliner_orthographic'])
def test_gridliner_orthographic():
plt.figure(figsize=(4, 4))
ax = plt.subplot(111, projection=ccrs.Orthographic())
ax.gridlines(ccrs.PlateCarree())


def test_gridliner_specified_lines():
meridians = [0, 60, 120, 180, 240, 360]
parallels = [-90, -60, -30, 0, 30, 60, 90]
Expand Down

0 comments on commit da219bc

Please sign in to comment.