diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index f0e018c8068e..a6a163843a6a 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -1326,7 +1326,13 @@ def _check_1d(x): return np.atleast_1d(x) else: try: - x[:, None] + ndim = x[:, None].ndim + # work around https://github.com/pandas-dev/pandas/issues/27775 + # which mean the shape is not as expected. That this ever worked + # was an unintentional quirk of pandas the above line will raise + # an exception in the future. + if ndim < 2: + return np.atleast_1d(x) return x except (IndexError, TypeError): return np.atleast_1d(x) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index abe33dcf0491..7daace9a43aa 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -5552,6 +5552,12 @@ def test_pandas_errorbar_indexing(pd): ax.errorbar('x', 'y', xerr='xe', yerr='ye', data=df) +def test_pandas_index_shape(pd): + df = pd.DataFrame({"XX": [4, 5, 6], "YY": [7, 1, 2]}) + fig, ax = plt.subplots() + ax.plot(df.index, df['YY']) + + def test_pandas_indexing_hist(pd): ser_1 = pd.Series(data=[1, 2, 2, 3, 3, 4, 4, 4, 4, 5]) ser_2 = ser_1.iloc[1:]