From 4f79ce0d9dff66f0558b7b1af5b5904c940e067f Mon Sep 17 00:00:00 2001 From: dcherian Date: Sat, 29 Sep 2018 20:22:19 +0900 Subject: [PATCH] plot.contour: Don't make cmap if colors is a single color. By default, matplotlib draw dashed negative contours for a single color. We lost this feature by manually specifying cmap everytime. --- doc/whats-new.rst | 4 ++++ xarray/plot/plot.py | 5 +++++ xarray/tests/test_plot.py | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 8b145924f2d..fba72f8a6fb 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -63,6 +63,10 @@ Bug fixes - ``xarray.DataArray.std()`` now correctly accepts ``ddof`` keyword argument. (:issue:`2240`) By `Keisuke Fujii `_. +- Restore matplotlib's default of plotting dashed negative contours when + a single color is passed to ``DataArray.contour()`` e.g. ``colors='k'``. + By `Deepak Cherian `_. + .. _whats-new.0.10.9: diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index a6add44682f..3f9f1090c70 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -737,6 +737,11 @@ def newplotfunc(darray, x=None, y=None, figsize=None, size=None, # pcolormesh kwargs['extend'] = cmap_params['extend'] kwargs['levels'] = cmap_params['levels'] + # if colors == a single color, matplotlib draws dashed negative + # contours. we lose this feature if we pass cmap and not colors + if isinstance(colors, basestring): + cmap_params['cmap'] = None + kwargs['colors'] = colors if 'pcolormesh' == plotfunc.__name__: kwargs['infer_intervals'] = infer_intervals diff --git a/xarray/tests/test_plot.py b/xarray/tests/test_plot.py index 1423f7ae853..98265149122 100644 --- a/xarray/tests/test_plot.py +++ b/xarray/tests/test_plot.py @@ -1140,9 +1140,9 @@ def test_colors(self): def _color_as_tuple(c): return tuple(c[:3]) + # with single color, we don't want rgb array artist = self.plotmethod(colors='k') - assert _color_as_tuple(artist.cmap.colors[0]) == \ - (0.0, 0.0, 0.0) + assert artist.cmap.colors[0] == 'k' artist = self.plotmethod(colors=['k', 'b']) assert _color_as_tuple(artist.cmap.colors[1]) == \