Skip to content

Commit 0f70a87

Browse files
dcherianshoyer
authored andcommitted
plot.contour: Don't make cmap if colors is a single color. (#2453)
By default, matplotlib draw dashed negative contours for a single color. We lost this feature by manually specifying cmap everytime.
1 parent 1e7a1d3 commit 0f70a87

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

doc/whats-new.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ Bug fixes
6868
- ``xarray.DataArray.std()`` now correctly accepts ``ddof`` keyword argument.
6969
(:issue:`2240`)
7070
By `Keisuke Fujii <https://github.com/fujiisoup>`_.
71+
- Restore matplotlib's default of plotting dashed negative contours when
72+
a single color is passed to ``DataArray.contour()`` e.g. ``colors='k'``.
73+
By `Deepak Cherian <https://github.com/dcherian>`_.
74+
7175

7276
.. _whats-new.0.10.9:
7377

xarray/plot/plot.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,11 @@ def newplotfunc(darray, x=None, y=None, figsize=None, size=None,
737737
# pcolormesh
738738
kwargs['extend'] = cmap_params['extend']
739739
kwargs['levels'] = cmap_params['levels']
740+
# if colors == a single color, matplotlib draws dashed negative
741+
# contours. we lose this feature if we pass cmap and not colors
742+
if isinstance(colors, basestring):
743+
cmap_params['cmap'] = None
744+
kwargs['colors'] = colors
740745

741746
if 'pcolormesh' == plotfunc.__name__:
742747
kwargs['infer_intervals'] = infer_intervals

xarray/tests/test_plot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1140,9 +1140,9 @@ def test_colors(self):
11401140
def _color_as_tuple(c):
11411141
return tuple(c[:3])
11421142

1143+
# with single color, we don't want rgb array
11431144
artist = self.plotmethod(colors='k')
1144-
assert _color_as_tuple(artist.cmap.colors[0]) == \
1145-
(0.0, 0.0, 0.0)
1145+
assert artist.cmap.colors[0] == 'k'
11461146

11471147
artist = self.plotmethod(colors=['k', 'b'])
11481148
assert _color_as_tuple(artist.cmap.colors[1]) == \

0 commit comments

Comments
 (0)