Skip to content

Commit 6fcf4fe

Browse files
committed
Fixes.
1 parent c44d8d0 commit 6fcf4fe

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

xarray/plot/utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,13 @@ def _determine_cmap_params(plot_data, vmin=None, vmax=None, cmap=None,
265265
if extend is None:
266266
extend = _determine_extend(calc_data, vmin, vmax)
267267

268+
cmap_is_colormap = (
269+
isinstance(cmap, mpl.colors.Colormap)
270+
or isinstance(cmap, mpl.colors.LinearSegmentedColormap)
271+
)
272+
268273
if ((levels is not None or isinstance(norm, mpl.colors.BoundaryNorm))
269-
and not isinstance(cmap, mpl.colors.Colormap)):
274+
and (not cmap_is_colormap)):
270275
cmap, newnorm = _build_discrete_cmap(cmap, levels, extend, filled)
271276
norm = newnorm if norm is None else norm
272277

xarray/tests/test_plot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,11 @@ def test_cmap_sequential_option(self):
537537
cmap_params = _determine_cmap_params(self.data)
538538
assert cmap_params['cmap'] == 'magma'
539539

540-
def test_do_nothing_if_provided_cmap(self):
541-
cmap = mpl.colors.LinearSegmentedColormap.from_list(
542-
'name', ['r', 'g', 'b'])
540+
@pytest.mark.parametrize(
541+
'cmap', [mpl.colors.LinearSegmentedColormap.from_list('name', ['r', 'g', 'b']),
542+
mpl.colors.ListedColormap(['r', 'g', 'b']),
543+
'RdBu_r'])
544+
def test_do_nothing_if_provided_cmap(self, cmap):
543545
cmap_params = _determine_cmap_params(self.data, cmap=cmap)
544546
assert cmap_params['cmap'] is cmap
545547

0 commit comments

Comments
 (0)