Repository: holoviz/holoviews

Issue:
Overlaying bar plots created using `xarray.DataArray.hvplot.bar` is broken
Overlaying bar plots created using `xarray.DataArray.hvplot.bar` does not work anymore.

#5835 may be related

#### ALL software version info
(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc)

```
xarray       : 2023.3.0
bokeh        : 3.2.1
matplotlib   : 3.7.1
pandas       : 1.5.3
ipywidgets   : 8.0.6
holoviews    : 1.17.0
sys          : 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:08:06) [GCC 11.3.0]
hvplot       : 0.8.3
```

#### Description of expected behavior and the observed behavior

On bokeh < 3, everything worked well. Now I get a blank plot

<img width="848" alt="image" src="https://github.com/holoviz/holoviews/assets/2448579/ac26396b-444f-4ade-bf6b-368741c31b46">

#### Complete, minimal, self-contained example code that reproduces the issue

```python
import xarray as xr
import hvplot.xarray

da = xr.DataArray(
    [1, 2, 3, 4, 5],
    dims="time",
    coords={"time": np.arange(5)},
    name="a",
)

da.isel(time=slice(2)).hvplot.bar() * da.isel(time=slice(2, None)).hvplot.bar()

```


Discussion:

Resolving patch:
diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py
--- a/holoviews/plotting/bokeh/element.py
+++ b/holoviews/plotting/bokeh/element.py
@@ -1713,9 +1713,7 @@ def _find_axes(self, plot, element):
         Looks up the axes and plot ranges given the plot and an element.
         """
         axis_dims = self._get_axis_dims(element)[:2]
-        if self.invert_axes:
-            axis_dims[0], axis_dims[1] = axis_dims[::-1]
-        x, y = axis_dims
+        x, y = axis_dims[::-1] if self.invert_axes else axis_dims
         if isinstance(x, Dimension) and x.name in plot.extra_x_ranges:
             x_range = plot.extra_x_ranges[x.name]
             xaxes = [xaxis for xaxis in plot.xaxis if xaxis.x_range_name == x.name]
diff --git a/holoviews/plotting/mixins.py b/holoviews/plotting/mixins.py
--- a/holoviews/plotting/mixins.py
+++ b/holoviews/plotting/mixins.py
@@ -161,7 +161,7 @@ def get_extents(self, element, ranges, range_type='combined', **kwargs):
         s1 = max(s1, 0) if util.isfinite(s1) else 0
         ranges[vdim]['soft'] = (s0, s1)
         if range_type not in ('combined', 'data'):
-            return super().get_extents(element, ranges, range_type)
+            return super().get_extents(element, ranges, range_type, ydim=element.vdims[0])
 
         # Compute stack heights
         xdim = element.kdims[0]


Test patch:
diff --git a/holoviews/tests/plotting/bokeh/test_barplot.py b/holoviews/tests/plotting/bokeh/test_barplot.py
--- a/holoviews/tests/plotting/bokeh/test_barplot.py
+++ b/holoviews/tests/plotting/bokeh/test_barplot.py
@@ -1,10 +1,10 @@
 import numpy as np
 
-from holoviews.core.overlay import NdOverlay
+from holoviews.core.overlay import NdOverlay, Overlay
 from holoviews.element import Bars
 from holoviews.plotting.bokeh.util import property_to_dict
 
-from bokeh.models import CategoricalColorMapper, LinearColorMapper
+from bokeh.models import CategoricalColorMapper, LinearColorMapper, LinearAxis
 
 from ..utils import ParamLogStream
 from .test_plot import TestBokehPlot, bokeh_renderer
@@ -65,6 +65,15 @@ def test_box_whisker_multi_level_sorted_alphanumerically(self):
         self.assertEqual(x_range.factors, [
             ('1', 'A'), ('1', 'B'), ('3', 'A'), ('3', 'B'), ('10', 'A'), ('10', 'B')])
 
+    def test_bars_multi_level_two_factors_in_overlay(self):
+        # See: https://github.com/holoviz/holoviews/pull/5850
+        box= Bars((["1", "2", "3"]*10, ['A', 'B']*15, np.random.randn(30)),
+                  ['Group', 'Category'], 'Value').aggregate(function=np.mean)
+        overlay = Overlay([box])
+        plot = bokeh_renderer.get_plot(overlay)
+        left_axis = plot.handles["plot"].left[0]
+        assert isinstance(left_axis, LinearAxis)
+
     def test_bars_positive_negative_mixed(self):
         bars = Bars([('A', 0, 1), ('A', 1, -1), ('B', 0, 2)],
                     kdims=['Index', 'Category'], vdims=['Value'])