Repository: scipp/plopp

Issue:
Axis mislabeled with 2-D coord that is "transposed"
Example:
```python
import scipp as sc
import plopp as pp

a = sc.linspace('a', 0,1,10, unit='m')
b = sc.linspace('b', 0,2,5, unit='s')

da = sc.DataArray(a*b, coords={'a':a, 'b':b*a})
da.plot()
```
Yields
<img width="536" alt="image" src="https://github.com/scipp/plopp/assets/12912489/c4c82432-7dab-4323-9799-af4805d786e7">

Note that the unit is correct, but apparently Plopp uses the name of the inner dim of a coord to get the axis name.


Discussion:

Patch:
diff --git a/src/plopp/graphics/imageview.py b/src/plopp/graphics/imageview.py
index 952c6b7..4929eea 100644
--- a/src/plopp/graphics/imageview.py
+++ b/src/plopp/graphics/imageview.py
@@ -130,8 +130,8 @@ class ImageView(View):
             self.canvas.set_axes(
                 dims={'x': xdim, 'y': ydim}, units={'x': xcoord.unit, 'y': ycoord.unit}
             )
-            self.canvas.xlabel = name_with_unit(var=xcoord)
-            self.canvas.ylabel = name_with_unit(var=ycoord)
+            self.canvas.xlabel = name_with_unit(var=xcoord, name=xdim)
+            self.canvas.ylabel = name_with_unit(var=ycoord, name=ydim)
             self.colormapper.unit = new_values.unit
             if xdim in self._scale:
                 self.canvas.xscale = self._scale[xdim]


Test patch:
diff --git a/tests/graphics/imageview_test.py b/tests/graphics/imageview_test.py
index 8a56217..fa6b715 100644
--- a/tests/graphics/imageview_test.py
+++ b/tests/graphics/imageview_test.py
@@ -128,3 +128,14 @@ def test_colorbar_label_has_no_name_with_multiple_artists():
     b.name = 'B data'
     fig = ImageView(Node(a), Node(b))
     assert fig.canvas.cblabel == '[K]'
+
+
+def test_axis_label_with_transposed_2d_coord():
+    a = sc.linspace('a', 0, 1, 10, unit='m')
+    b = sc.linspace('b', 0, 2, 5, unit='s')
+    da = sc.DataArray(a * b, coords={'a': a, 'b': b * a})
+    fig = ImageView(Node(da))
+    assert fig.canvas.xlabel == 'b [m*s]'
+    da = sc.DataArray(a * b, coords={'a': a, 'b': a * b})
+    fig2 = ImageView(Node(da))
+    assert fig2.canvas.xlabel == fig.canvas.xlabel