Skip to content

Commit f905289

Browse files
author
Joe Hamman
committed
Merge pull request #782 from jhamman/feature/cartopy_pcolormesh
dont infer interval breaks in pcolormesh when ax is a cartopy axis
2 parents 4dba0f9 + e3c17ea commit f905289

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

doc/whats-new.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ two DataArrays along their shared dims
5555
Bug fixes
5656
~~~~~~~~~
5757

58+
- Fixed an issue where plots using pcolormesh and Cartopy axes were being distorted
59+
by the inference of the axis interval breaks. This change chooses not to modify
60+
the coordinate variables when the axes have the attribute ``projection``, allowing
61+
Cartopy to handle the extent of pcolormesh plots (:issue:`781`).
62+
5863
.. _whats-new.0.7.1:
5964

6065
v0.7.1 (16 February 2016)

xarray/plot/plot.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,10 @@ def pcolormesh(x, y, z, ax, **kwargs):
540540
541541
Wraps matplotlib.pyplot.pcolormesh
542542
"""
543-
x = _infer_interval_breaks(x)
544-
y = _infer_interval_breaks(y)
543+
544+
if not hasattr(ax, 'projection'):
545+
x = _infer_interval_breaks(x)
546+
y = _infer_interval_breaks(y)
545547

546548
primitive = ax.pcolormesh(x, y, z, **kwargs)
547549

xarray/test/test_plot.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import xarray.plot as xplt
99
from xarray.plot.plot import _infer_interval_breaks
1010
from xarray.plot.utils import (_determine_cmap_params,
11-
_build_discrete_cmap,
12-
_color_palette)
11+
_build_discrete_cmap,
12+
_color_palette)
1313

1414
from . import TestCase, requires_matplotlib, incompatible_2_6
1515

@@ -773,6 +773,16 @@ def test_2d_coord_names(self):
773773
self.assertEqual('x2d', ax.get_xlabel())
774774
self.assertEqual('y2d', ax.get_ylabel())
775775

776+
def test_dont_infer_interval_breaks_for_cartopy(self):
777+
# Regression for GH 781
778+
ax = plt.gca()
779+
# Simulate a Cartopy Axis
780+
setattr(ax, 'projection', True)
781+
artist = self.plotmethod(x='x2d', y='y2d', ax=ax)
782+
self.assertTrue(isinstance(artist, mpl.collections.QuadMesh))
783+
# Let cartopy handle the axis limits and artist size
784+
self.assertTrue(artist.get_array().size <= self.darray.size)
785+
776786

777787
class TestImshow(Common2dMixin, PlotTestCase):
778788

0 commit comments

Comments
 (0)