Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot.contour: Don't make cmap if colors is a single color. #2453

Merged
merged 1 commit into from
Oct 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,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