Repository: scipp/plopp

Issue:
coord arg accepts multiple coords for same dimension
The `coords` argument accepts multiple coords for the same dimension and uses the last one in the list:
![Screenshot_20240904_100350](https://github.com/user-attachments/assets/4b6e2366-8b18-471f-aa7e-8f1ed301d46e)

This is surprising to me. Should it instead raise an error?

Discussion:

Patch:
diff --git a/src/plopp/plotting/common.py b/src/plopp/plotting/common.py
index 155fb88..08cdc36 100644
--- a/src/plopp/plotting/common.py
+++ b/src/plopp/plotting/common.py
@@ -196,6 +196,11 @@ def preprocess(
             coords = [coords]
         for dim in coords:
             underlying = out.coords[dim].dims[-1]
+            if underlying in renamed_dims:
+                raise ValueError(
+                    "coords: Cannot use more than one coordinate associated with "
+                    f"the same underlying dimension ({underlying})."
+                )
             renamed_dims[underlying] = dim
         out = out.rename_dims(**renamed_dims)
     for n, coord in out.coords.items():


Test patch:
diff --git a/tests/plotting/plot_2d_test.py b/tests/plotting/plot_2d_test.py
index 214e1e0..d5ed7d0 100644
--- a/tests/plotting/plot_2d_test.py
+++ b/tests/plotting/plot_2d_test.py
@@ -87,6 +87,16 @@ def test_use_non_dimension_coords():
     assert p.canvas.ymax == 3.3 * da.coords['yy'].max().value
 
 
+def test_use_two_coords_for_same_underlying_dimension_raises():
+    da = data_array(ndim=2)
+    da.coords['a'] = da.coords['xx'] * 2
+    msg = "coords: Cannot use more than one coordinate"
+    with pytest.raises(ValueError, match=msg):
+        pp.plot(da, coords=['xx', 'a'])
+    with pytest.raises(ValueError, match=msg):
+        pp.plot(da, coords=['a', 'xx'])
+
+
 @pytest.mark.parametrize('ext', ['jpg', 'png', 'pdf', 'svg'])
 def test_save_to_disk_2d(ext):
     da = data_array(ndim=2)