Repository: holoviz/holoviews
Pull request #6272 (2024-06-10 09:54:59)

Disable batching when subcoordinate_y is enabled
Batching kicks in when you are plotting more than `legend_limit` elements inside an `NdOverlay`. However for a `subcoordinate_y` plot batching is not and cannot be supported since each element has to be plotted using a different renderer instance. Therefore we check if `subcoordinate_y` is enabled before enabling batching.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/holoviz/holoviews/pull/6272?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=holoviz) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 87.85%. Comparing base [(`fc6e48b`)](https://app.codecov.io/gh/holoviz/holoviews/commit/fc6e48b18a5cdb449cd106b601e95edd89ea105a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=holoviz) to head [(`f67319b`)](https://app.codecov.io/gh/holoviz/holoviews/commit/f67319bd357b7cd3e26be3233ad6a12985dfa957?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=holoviz).


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##             main    #6272      +/-   ##
==========================================
- Coverage   88.53%   87.85%   -0.69%     
==========================================
  Files         323      323              
  Lines       67934    67940       +6     
==========================================
- Hits        60146    59687     -459     
- Misses       7788     8253     +465     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/holoviz/holoviews/pull/6272?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=holoviz).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=holoviz).


Patch:
diff --git a/holoviews/plotting/bokeh/element.py b/holoviews/plotting/bokeh/element.py
index ae500ffb1..8015bd1e6 100644
--- a/holoviews/plotting/bokeh/element.py
+++ b/holoviews/plotting/bokeh/element.py
@@ -3004,6 +3004,10 @@ class OverlayPlot(GenericOverlayPlot, LegendPlot):
                 return v._y_range_type
         return self._y_range_type
 
+    @property
+    def _is_batched(self):
+        return super()._is_batched and not self.subcoordinate_y
+
     def _process_legend(self, overlay):
         plot = self.handles['plot']
         subplots = self.traverse(lambda x: x, [lambda x: x is not self])
diff --git a/holoviews/plotting/plot.py b/holoviews/plotting/plot.py
index 774842989..6ac6ef052 100644
--- a/holoviews/plotting/plot.py
+++ b/holoviews/plotting/plot.py
@@ -1797,10 +1797,14 @@ class GenericOverlayPlot(GenericElementPlot):
             collapsed = Compositor.collapse(holomap, (ranges, frame_ranges.keys()), mode='display')
         return collapsed
 
+    @property
+    def _is_batched(self):
+        return self.batched and type(self.hmap.last) is NdOverlay
+
     def _create_subplots(self, ranges):
         # Check if plot should be batched
         ordering = util.layer_sort(self.hmap)
-        batched = self.batched and type(self.hmap.last) is NdOverlay
+        batched = self._is_batched
         if batched:
             backend = self.renderer.backend
             batchedplot = Store.registry[backend].get(self.hmap.last.type)


Test patch:
diff --git a/holoviews/tests/core/test_layers.py b/holoviews/tests/core/test_layers.py
index 35a21e261..5eb0acb69 100644
--- a/holoviews/tests/core/test_layers.py
+++ b/holoviews/tests/core/test_layers.py
@@ -2,7 +2,7 @@ import unittest
 
 import numpy as np
 
-from holoviews import Element, NdOverlay
+from holoviews import Curve, Element, NdOverlay, Overlay
 
 
 class CompositeTest(unittest.TestCase):
@@ -29,6 +29,12 @@ class OverlayTest(CompositeTest):
         for el, v in zip(overlay, views):
             self.assertEqual(el, v)
 
+    def test_overlay_iterable(self):
+        # Related to https://github.com/holoviz/holoviews/issues/5315
+        c1 = Curve([0, 1])
+        c2 = Curve([10, 20])
+        Overlay({'a': c1, 'b': c2}.values())
+
     def test_overlay_integer_indexing(self):
         overlay = NdOverlay(list(enumerate([self.view1, self.view2, self.view3])))
         self.assertEqual(overlay[0], self.view1)
diff --git a/holoviews/tests/plotting/bokeh/test_overlayplot.py b/holoviews/tests/plotting/bokeh/test_overlayplot.py
index 1678ce53e..bfca27b19 100644
--- a/holoviews/tests/plotting/bokeh/test_overlayplot.py
+++ b/holoviews/tests/plotting/bokeh/test_overlayplot.py
@@ -278,11 +278,15 @@ class TestOverlayPlot(LoggingComparisonTestCase, TestBokehPlot):
         _, vline_plot = plot.subplots.values()
         assert vline_plot.handles['glyph'].location == 1
 
-    def test_overlay_iterable(self):
-        # Related to https://github.com/holoviz/holoviews/issues/5315
-        c1 = Curve([0, 1])
-        c2 = Curve([10, 20])
-        Overlay({'a': c1, 'b': c2}.values())
+    def test_ndoverlay_subcoordinate_y_no_batching(self):
+        overlay = NdOverlay({
+            i: Curve(np.arange(10)*i).opts(subcoordinate_y=True) for i in range(10)
+        }).opts(legend_limit=1)
+        plot = bokeh_renderer.get_plot(overlay)
+
+        assert plot.batched == False
+        assert len(plot.subplots) == 10
+
 
 
 class TestLegends(TestBokehPlot):