|
4 | 4 | import numpy as np
|
5 | 5 | import pandas as pd
|
6 | 6 | import pytest
|
7 |
| -from numpy.testing import assert_array_equal |
8 | 7 |
|
9 | 8 | import xarray as xr
|
10 | 9 | import xarray.plot as xplt
|
11 | 10 | from xarray import DataArray
|
12 |
| -from xarray.coding.times import _import_cftime |
13 | 11 | from xarray.plot.plot import _infer_interval_breaks
|
14 | 12 | from xarray.plot.utils import (
|
15 | 13 | _build_discrete_cmap, _color_palette, _determine_cmap_params,
|
@@ -539,6 +537,25 @@ def test_cmap_sequential_option(self):
|
539 | 537 | cmap_params = _determine_cmap_params(self.data)
|
540 | 538 | assert cmap_params['cmap'] == 'magma'
|
541 | 539 |
|
| 540 | + def test_do_nothing_if_provided_cmap(self): |
| 541 | + cmap_list = [ |
| 542 | + mpl.colors.LinearSegmentedColormap.from_list('name', ['r', 'g']), |
| 543 | + mpl.colors.ListedColormap(['r', 'g', 'b']) |
| 544 | + ] |
| 545 | + |
| 546 | + # can't parametrize with mpl objects when mpl is absent |
| 547 | + for cmap in cmap_list: |
| 548 | + cmap_params = _determine_cmap_params(self.data, |
| 549 | + cmap=cmap, |
| 550 | + levels=7) |
| 551 | + assert cmap_params['cmap'] is cmap |
| 552 | + |
| 553 | + def test_do_something_if_provided_str_cmap(self): |
| 554 | + cmap = 'RdBu_r' |
| 555 | + cmap_params = _determine_cmap_params(self.data, cmap=cmap, levels=7) |
| 556 | + assert cmap_params['cmap'] is not cmap |
| 557 | + assert isinstance(cmap_params['cmap'], mpl.colors.ListedColormap) |
| 558 | + |
542 | 559 | def test_cmap_sequential_explicit_option(self):
|
543 | 560 | with xr.set_options(cmap_sequential=mpl.cm.magma):
|
544 | 561 | cmap_params = _determine_cmap_params(self.data)
|
|
0 commit comments