8000 FIX: fix check_1d to also check for ndim · matplotlib/matplotlib@085b1f9 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit 085b1f9

Browse files
committed
FIX: fix check_1d to also check for ndim
1 parent f8cd2c9 commit 085b1f9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/matplotlib/cbook/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,9 @@ def _check_1d(x):
13331333
"""Convert scalars to 1D arrays; pass-through arrays as is."""
13341334
# Unpack in case of e.g. Pandas or xarray object
13351335
x = _unpack_to_numpy(x)
1336-
if not hasattr(x, 'shape') or len(x.shape) < 1:
1336+
if (not hasattr(x, 'shape') or
1337+
not hasattr(x, 'ndim') or
1338+
len(x.shape) < 1):
13371339
return np.atleast_1d(x)
13381340
else:
13391341
return x

lib/matplotlib/tests/test_units.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,22 @@ def test_empty_default_limits(quantity_converter):
264264
fig.draw_without_rendering()
265265
assert ax.get_ylim() == (0, 100)
266266
assert ax.get_xlim() == (28.5, 31.5)
267+
268+
269+
# test array-like objects...
270+
class Kernel:
271+
def __init__(self, array):
272+
self._array = np.asanyarray(array)
273+
274+
def __array__(self):
275+
return self._array
276+
277+
@property
278+
def shape(self):
279+
return self._array.shape
280+
281+
282+
def test_plot_kernel():
283+
# just a smoketest that fail
284+
kernel = Kernel([1, 2, 3, 4, 5])
285+
plt.plot(kernel)

0 commit comments

Comments
 (0)
0