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

Revert cmap fix #3038

Merged
merged 3 commits into from
Jun 22, 2019
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
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