Skip to content

dont infer interval breaks in pcolormesh when ax is a cartopy axis #782

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 4 additions & 2 deletions xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 12 additions & 2 deletions xarray/test/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):

Expand Down