Repository: scipp/plopp

Issue:
2-D plot given multiple inputs puts one image on top of the other, hiding the one below
```python
import scipp as sc
import plopp as pp

var1 = sc.ones(dims=['x', 'y'], shape=[200,300])
var2 = var1 * 100

pp.plot({'a':var1, 'b':var2})
```
plots `var2`. I guess it should raise instead?

Discussion:

Patch:
diff --git a/src/plopp/backends/matplotlib/canvas.py b/src/plopp/backends/matplotlib/canvas.py
index 547dfe9..545e3b9 100644
--- a/src/plopp/backends/matplotlib/canvas.py
+++ b/src/plopp/backends/matplotlib/canvas.py
@@ -230,6 +230,14 @@ class Canvas:
     def ylabel(self, lab: str):
         self.ax.set_ylabel(lab)
 
+    @property
+    def cblabel(self) -> str:
+        return self.cax.get_ylabel()
+
+    @cblabel.setter
+    def cblabel(self, lab: str):
+        self.cax.set_ylabel(lab)
+
     @property
     def xscale(self) -> str:
         return self.ax.get_xscale()
diff --git a/src/plopp/functions/plot.py b/src/plopp/functions/plot.py
index 3dec5a5..112c554 100644
--- a/src/plopp/functions/plot.py
+++ b/src/plopp/functions/plot.py
@@ -124,6 +124,13 @@ def plot(obj: Union[VariableLike, ndarray, Dict[str, Union[VariableLike, ndarray
                         mask_color=mask_color,
                         **common_args)
     elif ndim == 2:
+        if len(data_arrays) > 1:
+            raise ValueError(
+                'The plot function can only plot a single 2d data entry. If you want '
+                'to create multiple figures, see the documentation on subplots at '
+                'https://scipp.github.io/plopp/customization/subplots.html. If you '
+                'want to plot two images onto the same axes, use the lower-level '
+                'plopp.figure2d function.')
         return figure2d(*[input_node(da) for da in data_arrays],
                         aspect=aspect,
                         cbar=cbar,
diff --git a/src/plopp/graphics/colormapper.py b/src/plopp/graphics/colormapper.py
index 87efd60..b88556d 100644
--- a/src/plopp/graphics/colormapper.py
+++ b/src/plopp/graphics/colormapper.py
@@ -207,16 +207,22 @@ class ColorMapper:
         key:
             The id of the node that provided this data.
         """
-        if self.name is None:
-            if self.unit is None:
-                self.unit = data.unit
-            self.name = data.name
-            if self.cax is not None:
-                self.cax.set_ylabel(f'{self.name} [{self.unit}]')
+        if self.unit is None:
+            self.unit = data.unit
         elif data.unit != self.unit:
             raise ValueError(f'Incompatible unit: colormapper has unit {self.unit}, '
                              f'new data has unit {data.unit}.')
 
+        if self.name is None:
+            self.name = data.name
+        elif data.name != self.name:
+            self.name = ''
+        if self.cax is not None:
+            text = self.name
+            if self.unit is not None:
+                text += f'{" " if self.name else ""}[{self.unit}]'
+            self.cax.set_ylabel(text)
+
         old_bounds = np.array([self.vmin, self.vmax])
         self.autoscale(data=data)
 


Test patch:
diff --git a/tests/functions/plot_test.py b/tests/functions/plot_test.py
index 539dbe0..9252815 100644
--- a/tests/functions/plot_test.py
+++ b/tests/functions/plot_test.py
@@ -280,3 +280,11 @@ def test_save_to_disk_with_bad_extension_raises():
     fig = pp.plot(da)
     with pytest.raises(ValueError):
         fig.save(filename='plopp_fig2d.txt')
+
+
+def test_plot_raises_with_multiple_2d_inputs():
+    a = data_array(ndim=2)
+    b = 3.3 * a
+    with pytest.raises(ValueError,
+                       match='The plot function can only plot a single 2d data entry'):
+        pp.plot({'a': a, 'b': b})
diff --git a/tests/graphics/figimage_test.py b/tests/graphics/figimage_test.py
index b15aacb..50bd7bf 100644
--- a/tests/graphics/figimage_test.py
+++ b/tests/graphics/figimage_test.py
@@ -136,3 +136,26 @@ def test_converts_new_data_coordinate_units():
     c = b.copy()
     c.coords['xx'] = c.coords['xx'].to(unit='m')
     assert sc.identical(fig.artists[bnode.id]._data, c)
+
+
+def test_colorbar_label_has_correct_unit():
+    da = data_array(ndim=2, unit='K')
+    fig = FigImage(input_node(da))
+    assert fig.canvas.cblabel == '[K]'
+
+
+def test_colorbar_label_has_correct_name():
+    da = data_array(ndim=2, unit='K')
+    name = 'My Experimental Data'
+    da.name = name
+    fig = FigImage(input_node(da))
+    assert fig.canvas.cblabel == name + ' [K]'
+
+
+def test_colorbar_label_has_no_name_with_multiple_artists():
+    a = data_array(ndim=2, unit='K')
+    b = 3.3 * a
+    a.name = 'A data'
+    b.name = 'B data'
+    fig = FigImage(input_node(a), input_node(b))
+    assert fig.canvas.cblabel == '[K]'