# Dropping a patch warnings when panning in streamed plot

**URL:** <https://discourse.bokeh.org/t/dropping-a-patch-warnings-when-panning-in-streamed-plot/12593>\
**Category:** Community Support\
**Tags:** bokeh\
**Created:** [September 24, 2025, 8:52pm UTC](https://discourse.bokeh.org/t/dropping-a-patch-warnings-when-panning-in-streamed-plot/12593 "2025-09-24T20:52:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![herbcle](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/h/b3f665/32.png) [@herbcle](https://discourse.bokeh.org/u/herbcle)\
**Post date:** [September 24, 2025, 8:52pm UTC](https://discourse.bokeh.org/t/dropping-a-patch-warnings-when-panning-in-streamed-plot/12593/1 "2025-09-24T20:52:17Z")

</div>

I am using version 3.7.3 of Bokeh.

I know that the “Dropping a patch” warnings are just warnings, but they show up in the terminal and I don’t want the customers of the script I wrote have to see those over and over again. Here is an MRE that shows what is happening. When I run this, and use the Pan tool, I get many of those warnings. For example, this warning.

> WARNING:root:Dropping a patch because it contains a previously known reference (id=‘p1005’). Most of the time this is harmless and usually a result of updating a model on one side of a communications channel while it was being removed on the other end.

The line that causes the warnings is

> self.plot\_figure.x\_range = Range1d(0, self.\_iteration)

What am I doing wrong?

Thanks in advance!

```auto

from bokeh.models import ColumnDataSource, Range1d
from bokeh.models.tools import PanTool
from bokeh.plotting import figure
from bokeh.server.server import Server
from bokeh.application.application import Application
from bokeh.application.handlers import FunctionHandler

_time_between_callbacks_in_ms = 200

class _RealTimeOptimizerPlot(object):
 
    def __init__ (self, callback_period, doc):
 
        self.plot_figure = figure(
            tools=[PanTool(),],
            title="MRE for dropped patches when panning",
        )

        self._source_stream_dict = {
            'iteration': [],
            'y': [],
        }
        self._source = ColumnDataSource(self._source_stream_dict)

        self._iteration = 0
        self._y = 0

        self.plot_figure.line(
            x="iteration",
            y="y",
            source=self._source,
        )

        doc.add_periodic_callback(self._update, callback_period)
        doc.title = "MRE for dropped patches when panning"
        doc.add_root(self.plot_figure)

    def _update(self):
        self._source_stream_dict = {
            "iteration": [self._iteration],
            "y": [self._y],
            }
        self._source.stream(self._source_stream_dict)
        
        # the following line causes the "Dropping a patch" warnings when panning
        self.plot_figure.x_range = Range1d(0, self._iteration)
        
        self._iteration += 1.
        self._y += 0.25

def _make_realtime_plot_doc(doc):
    _RealTimeOptimizerPlot(
        _time_between_callbacks_in_ms,
        doc=doc,
    )

try:
    server = Server(
        {"/": Application(FunctionHandler(_make_realtime_plot_doc))},
        port=5123,
    )
    server.start()
    server.io_loop.add_callback(server.show, "/")
    server.io_loop.start()
except KeyboardInterrupt as e:
    print(
        f"Real-time optimization plot server stopped due to keyboard interrupt: {e}"
    )
except Exception as e:
    print(f"Error starting real-time optimization plot server: {e}")
finally:
    print("Stopping real-time optimization plot server")
    if "server" in globals():
        server.stop()

```

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [September 25, 2025, 12:07am UTC](https://discourse.bokeh.org/t/dropping-a-patch-warnings-when-panning-in-streamed-plot/12593/2 "2025-09-25T00:07:10Z")

</div>

I guess the first thing I’d note is that this was just reduced from `warning` to `debug` in a recently merged PR:

[Lower log level for "Dropping a patch" message by TheoMathurin · Pull Request #14617 · bokeh/bokeh · GitHub](https://github.com/bokeh/bokeh/pull/14617)

But that won’t land until version 3.9 is released. So if you need an immediate solution the quickest thing is probably just to raise the [Bokeh log level](https://docs.bokeh.org/en/latest/docs/reference/settings.html#log-level) to `error` or `critical`.

There is probably also a way to use Python’s built in log filtering APIs to suppress this, but the details of that are outside my expertise.

All that said, is there a reason you do this:

```python
self.plot_figure.x_range = Range1d(0, self._iteration)

```

instead of this:

```auto
self.plot_figure.x_range.start = 0
self.plot_figure.x_range.end = self._iteration

```

? The latter kind of update (i.e. _changing properties on existing objects_ instead of _replacing entire objects wholesale_) is always regarded as best-practice when possible. Replacing entire objects is a “heavyweight” operation that involves unhooking and hooking back up all kinds of property event listeners.

Alternatively, could a `DataRange1d` be used here to avoid setting the range manually altogether? Perhaps by configuring its `renderers` property if auto-ranging should only take some subset of glyphs into account.

---

<div class="post-metadata">

**Author:** ![herbcle](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/h/b3f665/32.png) [@herbcle](https://discourse.bokeh.org/u/herbcle)\
**Post date:** [September 25, 2025, 8:31pm UTC](https://discourse.bokeh.org/t/dropping-a-patch-warnings-when-panning-in-streamed-plot/12593/3 "2025-09-25T20:31:10Z")

</div>

@Bryan thanks for the quick response! My MRE was a little too minimal. I am actually plotting two lines and that’s why I was using the Range1d. To make the MRE I took out the second line to simplify things but still show the behavior.

But your suggestion to use DataRange1d could be my solution! I didn’t even know about it.

I used it in small scripts and it works great. I need to try it in my full, really complicated script now.

Thanks again.

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [September 25, 2025, 8:51pm UTC](https://discourse.bokeh.org/t/dropping-a-patch-warnings-when-panning-in-streamed-plot/12593/4 "2025-09-25T20:51:33Z")

</div>

> [@herbcle](#):
>
> I am actually plotting two lines and that’s why I was using the Range1d.

I guess I am misunderstanding something, but I’ll admit I don’t see why the number of lines should have any bearing on updating an existing range in place by setting `start` and `end` on it (preferred) vs replacing the entire range object with a new range object (to be avoided).

---

<div class="post-metadata">

**Author:** ![herbcle](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/h/b3f665/32.png) [@herbcle](https://discourse.bokeh.org/u/herbcle)\
**Post date:** [September 26, 2025, 7:02pm UTC](https://discourse.bokeh.org/t/dropping-a-patch-warnings-when-panning-in-streamed-plot/12593/5 "2025-09-26T19:02:21Z")

</div>

@Bryan thank you ! I wasn’t really aware of the importance of using start and end compared to making a new Range1d. That makes sense! Using start and end fixed my problem completely.

Thanks for the great help.

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [December 25, 2025, 7:02pm UTC](https://discourse.bokeh.org/t/dropping-a-patch-warnings-when-panning-in-streamed-plot/12593/6 "2025-12-25T19:02:40Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
