Skip to content

Commit

Permalink
plot.contour: Don't make cmap if colors is a single color. (#2453)
Browse files Browse the repository at this point in the history
By default, matplotlib draw dashed negative contours for a single color.
We lost this feature by manually specifying cmap everytime.
  • Loading branch information
dcherian authored and shoyer committed Oct 2, 2018
1 parent 1e7a1d3 commit 0f70a87
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ Bug fixes
- ``xarray.DataArray.std()`` now correctly accepts ``ddof`` keyword argument.
(:issue:`2240`)
By `Keisuke Fujii <https://github.com/fujiisoup>`_.
- 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 <https://github.com/dcherian>`_.


.. _whats-new.0.10.9:

Expand Down
5 changes: 5 additions & 0 deletions xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]) == \
Expand Down

0 comments on commit 0f70a87

Please sign in to comment.