Skip to content

Commit dbb54f8

Browse files
authored
Restore redirection for tricontourf for GeoPlotting (#222)
1 parent 5ecfd81 commit dbb54f8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

ultraplot/axes/plot.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4933,6 +4933,7 @@ def streamplot(self, x, y, u, v, c, **kwargs):
49334933
return m
49344934

49354935
@inputs._parse_triangulation_with_preprocess("x", "y", "z", keywords=["triangles"])
4936+
@inputs._preprocess_or_redirect("x", "y", "z")
49364937
@docstring._concatenate_inherited
49374938
@docstring._snippet_manager
49384939
def tricontour(self, *args, **kwargs):
@@ -4972,6 +4973,7 @@ def tricontour(self, *args, **kwargs):
49724973
return m
49734974

49744975
@inputs._parse_triangulation_with_preprocess("x", "y", "z", keywords=["triangles"])
4976+
@inputs._preprocess_or_redirect("x", "y", "z")
49754977
@docstring._concatenate_inherited
49764978
@docstring._snippet_manager
49774979
def tricontourf(self, *args, **kwargs):

ultraplot/tests/test_geographic.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,3 +607,37 @@ def test_cartesian_and_geo():
607607
ax[0]._apply_axis_sharing()
608608
assert mocked.call_count == 1
609609
return fig
610+
611+
612+
def test_check_tricontourf():
613+
"""
614+
Ensure that tricontour functions are getting
615+
the transform for GeoAxes.
616+
"""
617+
import cartopy.crs as ccrs
618+
619+
lon0 = 90
620+
lon = np.linspace(-180, 180, 10)
621+
lat = np.linspace(-90, 90, 10)
622+
lon2d, lat2d = np.meshgrid(lon, lat)
623+
624+
data = np.sin(3 * np.radians(lat2d)) * np.cos(2 * np.radians(lon2d))
625+
# Place a box with constant values in order to have a visual reference
626+
mask_box = (lon2d >= 0) & (lon2d <= 20) & (lat2d >= 0) & (lat2d <= 20)
627+
data[mask_box] = 1.5
628+
629+
lon, lat, data = map(np.ravel, (lon2d, lat2d, data))
630+
631+
fig, ax = uplt.subplots(proj="cyl", proj_kw={"lon0": lon0})
632+
original_func = ax[0]._call_native
633+
with mock.patch.object(
634+
ax[0],
635+
"_call_native",
636+
autospec=True,
637+
side_effect=original_func,
638+
) as mocked:
639+
for func in "tricontour tricontourf".split():
640+
getattr(ax[0], func)(lon, lat, data)
641+
assert "transform" in mocked.call_args.kwargs
642+
assert isinstance(mocked.call_args.kwargs["transform"], ccrs.PlateCarree)
643+
uplt.close(fig)

0 commit comments

Comments
 (0)