diff --git a/doc/whats-new.rst b/doc/whats-new.rst index a762f1b54a2..aef19c4dacc 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -53,6 +53,11 @@ Enhancements Bug fixes ~~~~~~~~~ +- Fixed an issue where plots using pcolormesh and Cartopy axes were being distorted + by the inference of the axis interval breaks. This change chooses not to modify + the coordinate variables when the axes have the attribute ``projection``, allowing + Cartopy to handle the extent of pcolormesh plots (:issue:`781`). + .. _whats-new.0.7.1: v0.7.1 (16 February 2016) diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index 51369355f0b..62906b6307b 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -540,8 +540,10 @@ def pcolormesh(x, y, z, ax, **kwargs): Wraps matplotlib.pyplot.pcolormesh """ - x = _infer_interval_breaks(x) - y = _infer_interval_breaks(y) + + if not hasattr(ax, 'projection'): + x = _infer_interval_breaks(x) + y = _infer_interval_breaks(y) primitive = ax.pcolormesh(x, y, z, **kwargs) diff --git a/xarray/test/test_plot.py b/xarray/test/test_plot.py index 6c029f22167..ba6de2cc7d5 100644 --- a/xarray/test/test_plot.py +++ b/xarray/test/test_plot.py @@ -8,8 +8,8 @@ import xarray.plot as xplt from xarray.plot.plot import _infer_interval_breaks from xarray.plot.utils import (_determine_cmap_params, - _build_discrete_cmap, - _color_palette) + _build_discrete_cmap, + _color_palette) from . import TestCase, requires_matplotlib, incompatible_2_6 @@ -773,6 +773,16 @@ def test_2d_coord_names(self): self.assertEqual('x2d', ax.get_xlabel()) self.assertEqual('y2d', ax.get_ylabel()) + def test_dont_infer_interval_breaks_for_cartopy(self): + # Regression for GH 781 + ax = plt.gca() + # Simulate a Cartopy Axis + setattr(ax, 'projection', True) + artist = self.plotmethod(x='x2d', y='y2d', ax=ax) + self.assertTrue(isinstance(artist, mpl.collections.QuadMesh)) + # Let cartopy handle the axis limits and artist size + self.assertTrue(artist.get_array().size <= self.darray.size) + class TestImshow(Common2dMixin, PlotTestCase):