Skip to content

Commit 6e0f5c1

Browse files
authored
Fix unequal slicing for Gridspec (#435)
1 parent 80e12ee commit 6e0f5c1

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

ultraplot/gridspec.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,24 @@
66
import itertools
77
import re
88
from collections.abc import MutableSequence
9+
from functools import wraps
910
from numbers import Integral
11+
from typing import List, Optional, Tuple, Union
1012

1113
import matplotlib.axes as maxes
1214
import matplotlib.gridspec as mgridspec
1315
import matplotlib.transforms as mtransforms
1416
import numpy as np
15-
from typing import List, Optional, Union, Tuple
16-
from functools import wraps
1717

1818
from . import axes as paxes
1919
from .config import rc
20-
from .internals import ic # noqa: F401
21-
from .internals import _not_none, docstring, warnings
20+
from .internals import (
21+
_not_none,
22+
docstring,
23+
ic, # noqa: F401
24+
warnings,
25+
)
2226
from .utils import _fontsize_to_pt, units
23-
from .internals import warnings
2427

2528
__all__ = ["GridSpec", "SubplotGrid"]
2629

@@ -1650,7 +1653,10 @@ def __getitem__(self, key):
16501653
)
16511654
new_key.append(encoded_keyi)
16521655
xs, ys = new_key
1653-
objs = grid[xs, ys]
1656+
if np.iterable(xs) and np.iterable(ys):
1657+
objs = grid[np.ix_(xs, ys)]
1658+
else:
1659+
objs = grid[xs, ys]
16541660
if hasattr(objs, "flat"):
16551661
objs = [obj for obj in objs.flat if obj is not None]
16561662
elif not isinstance(objs, list):

0 commit comments

Comments
 (0)