From 788abaf0339894c151afa188367dfd3ed26738e9 Mon Sep 17 00:00:00 2001 From: Thomas A Caswell Date: Thu, 21 Sep 2017 22:09:26 -0400 Subject: [PATCH] Backport PR #9168: Fix pcolormesh and DatetimeIndex error PR Summary Fixes issue with `DatetimeIndex` and `pcolormesh`: https://github.com/matplotlib/matplotlib/issues/9167 PR Checklist - [X ] Code is PEP 8 compliant --- lib/matplotlib/axes/_axes.py | 5 +++-- lib/matplotlib/tests/test_axes.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 402382587ccf..48126b6be55e 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -5620,7 +5620,8 @@ def pcolormesh(self, *args, **kwargs): X, Y, C = self._pcolorargs('pcolormesh', *args, allmatch=allmatch) Ny, Nx = X.shape - + X = X.ravel() + Y = Y.ravel() # unit conversion allows e.g. datetime objects as axis values self._process_unit_info(xdata=X, ydata=Y, kwargs=kwargs) X = self.convert_xunits(X) @@ -5628,7 +5629,7 @@ def pcolormesh(self, *args, **kwargs): # convert to one dimensional arrays C = C.ravel() - coords = np.column_stack((X.flat, Y.flat)).astype(float, copy=False) + coords = np.column_stack((X, Y)).astype(float, copy=False) collection = mcoll.QuadMesh(Nx - 1, Ny - 1, coords, antialiased=antialiased, shading=shading, diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index b96b525aa439..25a4fff43edc 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -4929,6 +4929,17 @@ def test_broken_barh_empty(): ax.broken_barh([], (.1, .5)) +def test_pandas_pcolormesh(): + pd = pytest.importorskip('pandas') + + time = pd.date_range('2000-01-01', periods=10) + depth = np.arange(20) + data = np.random.rand(20, 10) + + fig, ax = plt.subplots() + ax.pcolormesh(time, depth, data) + + def test_pandas_indexing_dates(): pd = pytest.importorskip('pandas')