Skip to content

Commit

Permalink
Merge branch 'master' into doc-fix-dask
Browse files Browse the repository at this point in the history
  • Loading branch information
shoyer committed Nov 29, 2017
2 parents 5fe8bec + 4b8339b commit d5de271
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Expand Up @@ -21,6 +21,10 @@ v0.10.1 (unreleased)
Enhancements
~~~~~~~~~~~~

- :py:func:`~plot.contourf()` learned to contour 2D variables that have both a 1D co-ordinate (e.g. time) and a 2D co-ordinate (e.g. depth as a function of time).
By `Deepak Cherian <https://github.com/dcherian>`_.


Bug fixes
~~~~~~~~~

Expand Down
7 changes: 7 additions & 0 deletions xarray/plot/plot.py
Expand Up @@ -453,6 +453,13 @@ def newplotfunc(darray, x=None, y=None, figsize=None, size=None,
yval = darray[ylab].values
zval = darray.to_masked_array(copy=False)

# check if we need to broadcast one dimension
if xval.ndim < yval.ndim:
xval = np.broadcast_to(xval, yval.shape)

if yval.ndim < xval.ndim:
yval = np.broadcast_to(yval, xval.shape)

# May need to transpose for correct x, y labels
# xlab may be the name of a coord, we have to check for dim names
if darray[xlab].dims[-1] == darray.dims[0]:
Expand Down
4 changes: 4 additions & 0 deletions xarray/tests/test_distributed.py
@@ -1,3 +1,5 @@
import sys

import pytest
import xarray as xr
from xarray.core.pycompat import suppress
Expand All @@ -23,6 +25,8 @@
ENGINES.append('h5netcdf')


@pytest.mark.xfail(sys.platform == 'win32',
reason='https://github.com/pydata/xarray/issues/1738')
@pytest.mark.parametrize('engine', ENGINES)
def test_dask_distributed_integration_test(loop, engine):
with cluster() as (s, _):
Expand Down
9 changes: 9 additions & 0 deletions xarray/tests/test_plot.py
Expand Up @@ -107,6 +107,15 @@ def test2d_nonuniform_calls_contourf(self):
a.coords['dim_1'] = [2, 1, 89]
self.assertTrue(self.contourf_called(a.plot.contourf))

def test2d_1d_2d_coordinates_contourf(self):
sz = (20, 10)
depth = easy_array(sz)
a = DataArray(easy_array(sz), dims=['z', 'time'],
coords={'depth': (['z', 'time'], depth),
'time': np.linspace(0, 1, sz[1])})

a.plot.contourf(x='time', y='depth')

def test3d(self):
self.darray.plot()

Expand Down

0 comments on commit d5de271

Please sign in to comment.