From 66dd55f3f7ad207c76522bfc0b9b09b443ffbac7 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 18 Dec 2025 06:47:50 +1000 Subject: [PATCH 1/3] the fix --- ultraplot/gridspec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultraplot/gridspec.py b/ultraplot/gridspec.py index 59de0f04..fc57ae3e 100644 --- a/ultraplot/gridspec.py +++ b/ultraplot/gridspec.py @@ -1650,7 +1650,7 @@ def __getitem__(self, key): ) new_key.append(encoded_keyi) xs, ys = new_key - objs = grid[xs, ys] + objs = grid[np.ix_(xs, ys)] if hasattr(objs, "flat"): objs = [obj for obj in objs.flat if obj is not None] elif not isinstance(objs, list): From 03eaf37211999d1c25ceeddbc5f03b26d27043a4 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 18 Dec 2025 07:19:25 +1000 Subject: [PATCH 2/3] add type checks --- ultraplot/gridspec.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/ultraplot/gridspec.py b/ultraplot/gridspec.py index fc57ae3e..3668e9c8 100644 --- a/ultraplot/gridspec.py +++ b/ultraplot/gridspec.py @@ -6,21 +6,24 @@ import itertools import re from collections.abc import MutableSequence +from functools import wraps from numbers import Integral +from typing import List, Optional, Tuple, Union import matplotlib.axes as maxes import matplotlib.gridspec as mgridspec import matplotlib.transforms as mtransforms import numpy as np -from typing import List, Optional, Union, Tuple -from functools import wraps from . import axes as paxes from .config import rc -from .internals import ic # noqa: F401 -from .internals import _not_none, docstring, warnings +from .internals import ( + _not_none, + docstring, + ic, # noqa: F401 + warnings, +) from .utils import _fontsize_to_pt, units -from .internals import warnings __all__ = ["GridSpec", "SubplotGrid"] @@ -1650,7 +1653,10 @@ def __getitem__(self, key): ) new_key.append(encoded_keyi) xs, ys = new_key - objs = grid[np.ix_(xs, ys)] + if isinstance(xs, (list, tuple, np.ndarray)) and isinstance(ys, (list, tuple, np.ndarray)): + objs = grid[np.ix_(xs, ys)] + else: + objs = grid[xs, ys] if hasattr(objs, "flat"): objs = [obj for obj in objs.flat if obj is not None] elif not isinstance(objs, list): From 5c56b4d8a704a209c79e1f2e4c156aae902dcf70 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 18 Dec 2025 07:22:29 +1000 Subject: [PATCH 3/3] replace with np equivalent --- ultraplot/gridspec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ultraplot/gridspec.py b/ultraplot/gridspec.py index 3668e9c8..63556ab0 100644 --- a/ultraplot/gridspec.py +++ b/ultraplot/gridspec.py @@ -1653,7 +1653,7 @@ def __getitem__(self, key): ) new_key.append(encoded_keyi) xs, ys = new_key - if isinstance(xs, (list, tuple, np.ndarray)) and isinstance(ys, (list, tuple, np.ndarray)): + if np.iterable(xs) and np.iterable(ys): objs = grid[np.ix_(xs, ys)] else: objs = grid[xs, ys]