Repository: scipp/plopp

Issue:
Plotting data with `vector3` dtype plots components
This was unexpected:

```python
import scipp as sc

sc.vectors(dims=['vec'], values=[[1,2,3],[4,5,6]], unit='m').plot()
```
<img width="509" alt="image" src="https://github.com/scipp/plopp/assets/12912489/051f4ee2-8af5-4abc-9352-211164bad73a">


I would have expected an error.

Discussion:

Patch:
diff --git a/src/plopp/plotting/common.py b/src/plopp/plotting/common.py
index 26e8dc0..fad0a35 100644
--- a/src/plopp/plotting/common.py
+++ b/src/plopp/plotting/common.py
@@ -75,17 +75,42 @@ def _check_size(da: sc.DataArray):
         )
 
 
-def check_not_binned(obj):
-    if obj.bins is not None:
-        params = ', '.join([f'{dim}=100' for dim in obj.dims])
+def check_not_binned(da: sc.DataArray):
+    """
+    Plopp cannot plot binned data.
+    This function will raise an error if the input data is binned.
+
+    Parameters
+    ----------
+    da:
+        The data array to be plotted.
+    """
+    if da.bins is not None:
+        params = ', '.join([f'{dim}=100' for dim in da.dims])
         raise ValueError(
             "Cannot plot binned data, it must be histogrammed first, "
-            f"e.g., using ``obj.hist()`` or obj.hist({params})``."
+            f"e.g., using ``da.hist()`` or da.hist({params})``."
             "See https://scipp.github.io/generated/functions/scipp.hist.html for "
             "more details."
         )
 
 
+def check_allowed_dtypes(da: sc.DataArray):
+    """
+    Currently, Plopp cannot plot data that contains vector and matrix dtypes.
+    This function will raise an error if the input data type is not supported.
+
+    Parameters
+    ----------
+    da:
+        The data array to be plotted.
+    """
+    if da.shape != da.values.shape:
+        raise TypeError(
+            f'The input has dtype {da.dtype} which is not supported by Plopp.'
+        )
+
+
 def _all_dims_sorted(var, order='ascending'):
     return all([sc.allsorted(var, dim, order=order) for dim in var.dims])
 
@@ -117,6 +142,7 @@ def preprocess(
     """
     out = _to_data_array(obj)
     check_not_binned(out)
+    check_allowed_dtypes(out)
     if not out.name:
         out.name = name
     if not ignore_size:


Test patch:
diff --git a/tests/plotting/common_test.py b/tests/plotting/common_test.py
index c062564..4cb605a 100644
--- a/tests/plotting/common_test.py
+++ b/tests/plotting/common_test.py
@@ -46,3 +46,27 @@ def test_preprocess_no_warning_if_dtype_cannot_be_sorted():
     )
     out = preprocess(da)  # no warning should be emitted
     assert 'strings' in out.coords
+
+
+@pytest.mark.parametrize(
+    'dtype_and_shape',
+    [
+        (sc.DType.affine_transform3, (4, 4)),
+        (sc.DType.linear_transform3, (3, 3)),
+        (sc.DType.rotation3, (4,)),
+        (sc.DType.translation3, (3,)),
+        (sc.DType.vector3, (3,)),
+    ],
+)
+def test_preprocess_raises_for_unsupported_dtype(dtype_and_shape):
+    dtype, shape = dtype_and_shape
+    x = np.random.random(shape + (5,))
+    values = x / np.broadcast_to(
+        np.linalg.norm(x, axis=tuple(range(len(shape)))), x.shape
+    )
+    v = sc.Variable(dims=['x'], values=values.T, dtype=dtype)
+    with pytest.raises(
+        TypeError,
+        match=f'The input has dtype {dtype} which is not supported by Plopp',
+    ):
+        preprocess(v)