Skip to content

Commit

Permalink
Revert cmap fix (#3038)
Browse files Browse the repository at this point in the history
* Test for levels + provided cmap

* Revert "plot: If provided with colormap do not modify it. (#2935)"

This reverts commit ab39722.

* lint
  • Loading branch information
dcherian authored and shoyer committed Jun 22, 2019
1 parent 9c0bbf7 commit 724ad83
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 28 deletions.
2 changes: 0 additions & 2 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ Bug fixes
By `Mayeul d'Avezac <https://github.com/mdavezac>`_.
- Return correct count for scalar datetime64 arrays (:issue:`2770`)
By `Dan Nowacki <https://github.com/dnowacki-usgs>`_.
- Fix facetgrid colormap bug when ``extend=True``. (:issue:`2932`)
By `Deepak Cherian <https://github.com/dcherian`_.
- A deep copy deep-copies the coords (:issue:`1463`)
By `Martin Pletcher <https://github.com/pletchm>`_.
- Increased support for `missing_value` (:issue:`2871`)
Expand Down
3 changes: 1 addition & 2 deletions xarray/plot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,7 @@ def _determine_cmap_params(plot_data, vmin=None, vmax=None, cmap=None,
if extend is None:
extend = _determine_extend(calc_data, vmin, vmax)

if ((levels is not None or isinstance(norm, mpl.colors.BoundaryNorm))
and (not isinstance(cmap, mpl.colors.Colormap))):
if levels is not None or isinstance(norm, mpl.colors.BoundaryNorm):
cmap, newnorm = _build_discrete_cmap(cmap, levels, extend, filled)
norm = newnorm if norm is None else norm

Expand Down
31 changes: 7 additions & 24 deletions xarray/tests/test_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import xarray as xr
import xarray.plot as xplt
from xarray import DataArray
from xarray.coding.times import _import_cftime
from xarray.plot.plot import _infer_interval_breaks
from xarray.plot.utils import (
_build_discrete_cmap, _color_palette, _determine_cmap_params,
Expand Down Expand Up @@ -537,25 +538,6 @@ def test_cmap_sequential_option(self):
cmap_params = _determine_cmap_params(self.data)
assert cmap_params['cmap'] == 'magma'

def test_do_nothing_if_provided_cmap(self):
cmap_list = [
mpl.colors.LinearSegmentedColormap.from_list('name', ['r', 'g']),
mpl.colors.ListedColormap(['r', 'g', 'b'])
]

# can't parametrize with mpl objects when mpl is absent
for cmap in cmap_list:
cmap_params = _determine_cmap_params(self.data,
cmap=cmap,
levels=7)
assert cmap_params['cmap'] is cmap

def test_do_something_if_provided_str_cmap(self):
cmap = 'RdBu_r'
cmap_params = _determine_cmap_params(self.data, cmap=cmap, levels=7)
assert cmap_params['cmap'] is not cmap
assert isinstance(cmap_params['cmap'], mpl.colors.ListedColormap)

def test_cmap_sequential_explicit_option(self):
with xr.set_options(cmap_sequential=mpl.cm.magma):
cmap_params = _determine_cmap_params(self.data)
Expand Down Expand Up @@ -775,13 +757,14 @@ def test_discrete_colormap_list_of_levels(self):

@pytest.mark.slow
def test_discrete_colormap_int_levels(self):
for extend, levels, vmin, vmax in [('neither', 7, None, None),
('neither', 7, None, 20),
('both', 7, 4, 8),
('min', 10, 4, 15)]:
for extend, levels, vmin, vmax, cmap in [
('neither', 7, None, None, None),
('neither', 7, None, 20, mpl.cm.RdBu),
('both', 7, 4, 8, None),
('min', 10, 4, 15, None)]:
for kind in ['imshow', 'pcolormesh', 'contourf', 'contour']:
primitive = getattr(self.darray.plot, kind)(
levels=levels, vmin=vmin, vmax=vmax)
levels=levels, vmin=vmin, vmax=vmax, cmap=cmap)
assert levels >= \
len(primitive.norm.boundaries) - 1
if vmax is None:
Expand Down

0 comments on commit 724ad83

Please sign in to comment.