|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | import numpy as np |
| 4 | +import pytest |
4 | 5 |
|
5 | 6 | import holoviews as hv |
6 | 7 | from holoviews.plotting.plotly.util import PLOTLY_MAP, PLOTLY_SCATTERMAP |
@@ -62,6 +63,24 @@ def test_scatter_categorical_color(self): |
62 | 63 | assert state["data"][0]["marker"]["cmin"] == 0 |
63 | 64 | assert state["data"][0]["marker"]["cmax"] == 2 |
64 | 65 |
|
| 66 | + def test_scatter_categorical_color_cmap_dict(self): |
| 67 | + scatter = hv.Scatter([(0, 1, "A"), (1, 2, "B")], vdims=["y", "category"]) |
| 68 | + scatter.opts(color="category", cmap={"A": "black", "B": "red"}) |
| 69 | + state = self._get_plot_state(scatter) |
| 70 | + |
| 71 | + marker = state["data"][0]["marker"] |
| 72 | + np.testing.assert_array_equal(marker["color"], [0, 1]) |
| 73 | + assert marker["colorscale"] == [[0, "black"], [1, "red"]] |
| 74 | + assert marker["cmin"] == 0 |
| 75 | + assert marker["cmax"] == 1 |
| 76 | + |
| 77 | + def test_scatter_categorical_color_cmap_dict_missing(self): |
| 78 | + scatter = hv.Scatter([(0, 1, "A"), (1, 2, "B")], vdims=["y", "category"]) |
| 79 | + scatter.opts(color="category", cmap={"A": "black"}) |
| 80 | + msg = "Missing color\\(s\\) for categories: 'B'" |
| 81 | + with pytest.raises(ValueError, match=msg): |
| 82 | + self._get_plot_state(scatter) |
| 83 | + |
65 | 84 | def test_scatter_markers(self): |
66 | 85 | scatter = hv.Scatter( |
67 | 86 | [(0, 1, "square"), (1, 2, "circle"), (2, 3, "triangle-up")], vdims=["y", "marker"] |
|
0 commit comments