Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
19 changes: 16 additions & 3 deletions ultraplot/internals/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,23 @@ def _preprocess_or_redirect(self, *args, **kwargs):
if kwargs.get("latlon", None) is None:
kwargs["latlon"] = True
if self._name == "cartopy" and name in CARTOPY_FUNCS:
if kwargs.get("transform", None) is None:
kwargs["transform"] = PlateCarree()
# Check if an input transform is given
# else default to axis projection or
# PlateCarree if no projection is set
input_transform = kwargs.get("transform", None)
if input_transform is not None:
kwargs["transform"] = Proj(input_transform)
else:
kwargs["transform"] = Proj(kwargs["transform"])
# add projection for imshow as it
# cannot be projected on particular
# locations
options = [
self.projection if name == "imshow" else None,
PlateCarree(),
]
kwargs["transform"] = _not_none(
*options,
)

# Process data args
# NOTE: Raises error if there are more args than keys
Expand Down
23 changes: 22 additions & 1 deletion ultraplot/tests/test_inputs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ultraplot as uplt, pytest, numpy as np
from unittest.mock import Mock
from unittest.mock import Mock, patch


@pytest.mark.parametrize(
Expand Down Expand Up @@ -33,3 +33,24 @@ def tripcolor(self, tri, z, extra=None, kw=None):

# Test that the decorator preserves the function name
assert decorated.__name__ == "tripcolor"


@pytest.mark.parametrize("transform", [None, uplt.constructor.Proj("merc")])
def test_projection_set_correctly(rng, transform):

fig, ax = uplt.subplots(proj="merc")
fig.canvas.draw()
data = rng.random((10, 10))

with patch.object(ax, "imshow", wraps=ax.imshow) as mock_imshow:
# Call imshow with some dummy data
settings = dict(transform=transform)
ax.imshow(data, **settings)

# Assert that the transform keyword argument was set correctly
mock_imshow.assert_called_once()
_, kwargs = mock_imshow.call_args
assert "transform" in kwargs, "The 'transform' keyword argument is missing."
assert (
kwargs["transform"] == transform
), f"Expected transform to be {expectation}, got {kwargs['transform']}"
Loading